
Image that shows the buttons before and after (nameOfButton).layer.zPosition = 99 is applied.
即使我的按钮位于标题前面,按钮点按也没有注册…
我正在以编程方式创建按钮,我的vIEwDIDLoad看起来像这样:
overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() // Allow iOS to resize the cells automatically according to our auto Layout constraints tableVIEw.rowHeight = UItableVIEwautomaticDimension // We will take ownership of the header vIEw we've so nicely setup in the storyboard and then remove it from the table vIEw. headerVIEw = tableVIEw.tableheaderVIEw tableVIEw.tableheaderVIEw = nil tableVIEw.addSubvIEw(headerVIEw) let addPhotoTapGesture = UITapGestureRecognizer(target: self,action: #selector(VIEwController.addPhoto(_:))) headerVIEw.addGestureRecognizer(addPhotoTapGesture) // Photopicker createPhotopickerbuttons() let effectiveHeight = ktableheaderHeight-ktableheaderCutAway/2 tableVIEw.contentInset = UIEdgeInsets(top: effectiveHeight,left: 0,bottom: 0,right: 0) tableVIEw.contentOffset = CGPoint(x: 0,y: -effectiveHeight) headerMaskLayer = CAShapeLayer() headerMaskLayer.fillcolor = UIcolor.blackcolor().CGcolor headerVIEw.layer.mask = headerMaskLayer updateheaderVIEw() } 还有我的createPhotopickerbuttons()(这里我将按钮放在视图下方,这样我就可以使用showImagePicker()为它们的外观设置动画:
func createPhotopickerbuttons() { takePhotobutton = UIbutton.init(type: UIbuttonType.System) // .System photolibrarybutton = UIbutton.init(type: UIbuttonType.System) // .System cancelbutton = UIbutton.init(type: UIbuttonType.System) // .System takePhotobutton.frame = CGRectMake(20,(0 + self.tableVIEw.contentOffset.y + UIScreen.mainScreen().bounds.height),(UIScreen.mainScreen().bounds.wIDth - 40),40) photolibrarybutton.frame = CGRectMake(20,40) cancelbutton.frame = CGRectMake(20,40) takePhotobutton.backgroundcolor = UIcolor(red: 0/255,green: 122/255,blue: 255/255,Alpha: 1.0) photolibrarybutton.backgroundcolor = UIcolor(red: 0/255,Alpha: 1.0) cancelbutton.backgroundcolor = UIcolor(red: 0/255,Alpha: 1.0) takePhotobutton.set@R_502_5979@("Take Photo",forState: UIControlState.normal) photolibrarybutton.set@R_502_5979@("Photo library",forState: UIControlState.normal) cancelbutton.set@R_502_5979@("Cancel",forState: UIControlState.normal) takePhotobutton.@R_502_5979@Label?.Font = UIFont.systemFontOfSize(17) photolibrarybutton.@R_502_5979@Label?.Font = UIFont.systemFontOfSize(17) cancelbutton.@R_502_5979@Label?.Font = UIFont.systemFontOfSize(17) takePhotobutton.set@R_502_5979@color(UIcolor.whitecolor(),forState: UIControlState.normal) photolibrarybutton.set@R_502_5979@color(UIcolor.whitecolor(),forState: UIControlState.normal) cancelbutton.set@R_502_5979@color(UIcolor.whitecolor(),forState: UIControlState.normal) let takePhotobuttonTapGesture = UITapGestureRecognizer(target: self,action: #selector(VIEwController.takePhotobuttonAction(_:))) takePhotobutton.addGestureRecognizer(takePhotobuttonTapGesture) let photolibrarybuttonTapGesture = UITapGestureRecognizer(target: self,action: #selector(VIEwController.photolibrarybuttonAction(_:))) photolibrarybutton.addGestureRecognizer(photolibrarybuttonTapGesture) let cancelbuttonTapGesture = UITapGestureRecognizer(target: self,action: #selector(VIEwController.cancelbuttonAction(_:))) cancelbutton.addGestureRecognizer(cancelbuttonTapGesture) self.tableVIEw.addSubvIEw(takePhotobutton) self.tableVIEw.addSubvIEw(photolibrarybutton) self.tableVIEw.addSubvIEw(cancelbutton) takePhotobutton.layer.zposition = 99 photolibrarybutton.layer.zposition = 99 cancelbutton.layer.zposition = 99 takePhotobutton.Alpha = 0 photolibrarybutton.Alpha = 0 cancelbutton.Alpha = 0 } 最后我的showImagePicker()在addPhoto()中调用(当用户点击图像时调用的动作):
func showImagePicker(){ // (0 + self.tableVIEw.contentOffset.y + UIScreen.mainScreen().bounds.height - 50 - 10 - 50 - 10 - 50 - 10) UIVIEw.animateWithDuration(0.5) { self.takePhotobutton.Alpha = 1 self.photolibrarybutton.Alpha = 1 self.cancelbutton.Alpha = 1 self.takePhotobutton.frame.origin.y = 0 + self.tableVIEw.contentOffset.y + UIScreen.mainScreen().bounds.height - 50 - 10 - 50 - 10 - 50 - 10 self.photolibrarybutton.frame.origin.y = 0 + self.tableVIEw.contentOffset.y + UIScreen.mainScreen().bounds.height - 50 - 10 - 50 - 10 self.cancelbutton.frame.origin.y = 0 + self.tableVIEw.contentOffset.y + UIScreen.mainScreen().bounds.height - 50 - 10 } } 我在SO上找不到任何关于这个的东西,也不知道tableVIEw中按钮的另一个解决方案.
解决方法 我花了一段时间才找到解决方案,但我弄清楚了:sectionVIEw.userInteractionEnabled = false
sectionVIEw.layer.zposition = -1
编辑:SWIFT 3更新:
vIEw.isUserInteractionEnabled = false@H_301_0@ 总结
以上是内存溢出为你收集整理的ios – Swift – UITableView中的标题阻止按钮交互全部内容,希望文章能够帮你解决ios – Swift – UITableView中的标题阻止按钮交互所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)