-1

I'm new in using swift and I have a problem when create it

I'm using swift 2 XCode 7

I have a button at the bottom of scrollview to submit all textfield that I put above but when I tap the button I have to hold for a few second before the button is tapped. I have search for a solution in a few web and there is a solution said that unchecked the Delays Content Touches but my scrollview become too hard to scroll so I checked another solution said that create a custom ScrollView, but after I created it, I can't tap my button.

This is several web that I found but no one worked

UIButton touch is delayed when in UIScrollView

UIButton not showing highlight on tap in iOS7 - Swift

Subclass UIScrollView in Swift for touches Began & touches Moved

Please give me some hint to some example how to fix this problem

Any help is appreciated

Community
  • 1
  • 1
Dirus
  • 1,033
  • 2
  • 14
  • 21
  • Possible that your button is out of bounds of scroll view so just set background color to all your views to test that and keep button clips to bounds = YES – Prashant Tukadiya May 12 '16 at 04:36
  • @PKT I think it is not my button is out of bounds but the problem itself comes from UIScrollView – Dirus May 12 '16 at 06:53

2 Answers2

-1

The best way to solve it is to separate button and scroll view frame. And the OS will not check the touch events is for button or for scroll view.

Update:

I'm wondering your button is subview of scroll view. Because I tested this view hierarchy and didn't get your issue:

enter image description here

Update 2: You can also do like above. At the same time,you should move that button whenever scroll view did scroll. This will look like they're together.

Another solution is to change response chain. You can get hit events in - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event of UIView. And if that point is in the frame of button, you should hit test button and return that result. Like this:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    if (!self.clipsToBounds && !self.hidden && self.alpha > 0.01) {
        CGPoint point = [button convertPoint:point fromView:scrollView];
        if (button frame contains point) {
            UIView *result = [button hitTest:point withEvent:event];
            if (result != nil) {
                return result;
            }
        } else {
            // hit the scroll view area outside button
        }
    }

    return nil;
}
Lumialxk
  • 6,239
  • 6
  • 24
  • 47
  • Seperate the frame makes my ScrollView frame not full in the phone, is there other way to make it works ? – Dirus May 12 '16 at 03:32
  • @Dirus I tested this and found something, here is my update. – Lumialxk May 12 '16 at 03:42
  • what I mean is like this https://i.imgsafe.org/1365e0b.png in the apps the frame is divided by two and all my form is only visible half – Dirus May 12 '16 at 06:52
  • @Dirus Updated my answer. I didn't test for this so maybe it will not work.But I believe it'll give you some thoughts. – Lumialxk May 12 '16 at 07:08
-1

If the button is at the bottom of the tableview, you could always add a row with a cell that acts as a button. Or add the button to the tableview footer.

Ben M.
  • 39
  • 2
  • I'm using UIScrollView not TableView so how to add UIButton at the bottom ? If I separate the frame, my ScrollView is frame is not full in the phone – Dirus May 12 '16 at 03:31
  • Oh sorry somehow I thought it was a tableview ... must of been an iteruption of my thought process. – Ben M. May 12 '16 at 07:25