问题描述
尝试制作一个 UIButton,当它长按时,会显示四个子视图(UIButtons - 北、东、南和西),然后用户可以将手指滑动到并抬起来进行 4 个单独的操作。
extension UIButton {
func EnablePopOuts (north:Bool = true,nTitle:String,nColor:UIColor = .black,nAction: Selector) {
if north {
let northButton = UIButton(frame: self.frame)
northButton.translatesAutoresizingMaskIntoConstraints = false
let nA = NSLayoutConstraint(item: northButton,attribute: .height,relatedBy: .equal,toItem: self,multiplier: 1,constant: 0)
let nB = NSLayoutConstraint(item: northButton,attribute: .width,constant: 0)
let nC = NSLayoutConstraint(item: northButton,attribute: .bottom,attribute: . top,constant: 0)
let nD = NSLayoutConstraint(item: northButton,attribute: .leading,constant: 0)
self.addSubview(northButton)
self.didAddSubview(northButton)
self.addConstraints([nA,nB,nC,nD])
self.bringSubviewToFront(northButton)
northButton.setTitle(nTitle,for: .normal)
northButton.backgroundColor = nColor
northButton.addTarget(Main.self,action: nAction,for: .touchUpInside)
self.layoutIfNeeded()
self.layoutSubviews()
}
}
}
EnablePopOuts
运行但北按钮没有出现。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)