UIButton delayed state change

后端 未结 5 1702
庸人自扰
庸人自扰 2020-12-31 03:31

I have a UIButton subview inside of a UITableViewCell.

When this button is touched, the user must hold the button for about a half second f

5条回答
  •  旧时难觅i
    2020-12-31 04:16

    Up for David Hodge's answer.

    I just want to add a way to remove that "only negative side effect", already described by David: if you start scrolling inside a UIcontrol in a UIScrollView with delayContentTouches=NO, scrolling doesn't work.

    SOLUTION Subclass UIScrollView (or UITableView as the original question) and override:

    -(BOOL) touchesShouldCancelInContentView:(UIView *)view {   
    return YES; 
    }
    

    Your UIControls inside UIScrollView/UITableView will change their state immediately on tap and the scrollviews will be able to scroll even if the touch starts on some UIControl. Works like a charm.

提交回复
热议问题