Uibutton Does Not Work When It in Uiscrollview

UIButton does not work when it in UIScrollView

Create a subclass of UIScrollview with

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

If you are not getting that message, set:

scrollView.delaysContentTouches = NO;

The problem is because of the way touchesShouldCancelInContentView behaves by default, it returns NO only if the subview is an UIControl, but your button is hidden inside the CustomView which isn't.

UIButtons at the bottom of UIScrollView not working

It seems you need to increase the frame height of container view. The contentSize of scrollView only affects how it will scroll, which is irrelevant here.

If the button is outside the container view, it will still show up. However, it can't respond to any touch event.

UIButton inside UIScrollView doesn't fire on tap

I found this stuff:

But the scrollview will block the
touches from the button unless you set
userInteractionEnabled and
exclusiveTouch properties to NO on the
scrollview. But that would defeat the
purpose of having a scrollview inside
a button I think.

(See Can we put a UIButton in a UIScrollView and vice versa in iPhone)

But how to do it?

Say you have a UIScrollView *sv ... then

sv.userInteractionEnabled = YES;
sv.exclusiveTouch = YES;

I would also add

sv.canCancelContentTouches = YES;
sv.delaysContentTouches = YES;

UIButton in custom UIScrollView class not responding to touches

After adding a constraint refreshing layout is a must

override func viewWillAppear(_ animated: Bool) {

scrollView.anchor(topLayoutGuide.bottomAnchor, left: view.leftAnchor, bottom: bottomLayoutGuide.topAnchor, right: view.rightAnchor, topConstant: 10, leftConstant: 10, bottomConstant: 10, rightConstant: 10, widthConstant: 0, heightConstant: 0)

self.view.layoutIfNeeded()
}

UIButton is not working/Clickable in UIScrollView

I had to provide (-)ve value for bottom space of the ContentView from the superview. It did the job. Initially it was set to zero and because of this there was a large extra space below the bottom and it made the scrolling larger that was not desired.

I have tested it in all the simulators - 4s to 6+ and it is working fine.

Thanks to Nikolay for his continuous help.

Also as I am completely new to iPhone development so I do not know whether my workaround is correct or not. So if there is another solution to the problem then please let me know.

UIButton at bottom of UIScrollView not working

call layoutIfNeeded() on your top view after creating your subviews if using any constraints.
make sure the scrollView's contentSize matches your containerView.frame (not .bounds, since this will not tell you if for instance your frame y-position is below zero.

UIButton Doesn't allow UIScrollView to scroll

As long as you have the Cancellable Content Touches in Interface Builder set it should work. You can also set it in code:

scrollView.canCancelContentTouches = YES;

UIButton inside UIView inside UIScrollView not firing tap action

Turn out that I was using a view controller's view and for some reason, the selectors don't work this way. So, what I did was to create a UIView only and then everything works just fine.



Related Topics



Leave a reply



Submit