How to prevent side area clickable of UIBarButtonI

2019-07-10 10:18发布

`Arrow display area which i want to prevent to click

Whenever i click on this area , action also perform on this.

3条回答
霸刀☆藐视天下
2楼-- · 2019-07-10 10:27

I got solution. I put one UIButton between these two UIBarButtonItem and make it custom and nil it's selector.

查看更多
乱世女痞
3楼-- · 2019-07-10 10:29

Also, you can try this: (Swift version)

    let btnName = UIButton()
    btnName.setImage(UIImage(named: "settings_filled_25"), forState: .Normal)
    btnName.frame = CGRectMake(0, 0, 30, 30)
    btnName.addTarget(self, action: Selector("toggleRight"), forControlEvents: .TouchUpInside)

    var rightView = UIView()
    rightView.frame = CGRectMake(0, 0, 30, 30)
    rightView.addSubview(btnName)

    let rightBarButton = UIBarButtonItem()
    rightBarButton.customView = rightView
    self.navigationItem.rightBarButtonItem = rightBarButton
查看更多
趁早两清
4楼-- · 2019-07-10 10:40

Don't worry about this behavior, iOS auto tapp near element if there is not other element.

If you really want to prevent to click except button, then you have to put Element on unused area which should be inherited from UIControl or able to get UserInteraction.

查看更多
登录 后发表回答