ios – Swift – UITableView中的标题阻止按钮交互

ios – Swift – UITableView中的标题阻止按钮交互,第1张

概述在我的UITableView中,我希望有一个选项可以单击一个具有固定位置的按钮(参见附图).但是UITableView节标题前面或后面的任何内容都被阻止了交互,它没有注册按钮点击.我试图设置一个更高的zPosition,它将按钮放在标题前面,但我仍然无法按下按钮.这就是它的样子: Image that shows the buttons before and after (nameOfButton @H_301_0@ @H_301_0@ 在我的UItableVIEw中,我希望有一个选项可以单击一个具有固定位置的按钮(参见附图).但是UItableVIEw节标题前面或后面的任何内容都被阻止了交互,它没有注册按钮点击.我试图设置一个更高的zposition,它将按钮放在标题前面,但我仍然无法按下按钮.这就是它的样子:

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中的标题阻止按钮交互所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1062284.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存