开发者

Get the touch for a view that is inside a scrolll view

开发者 https://www.devze.com 2023-04-05 21:40 出处:网络
I have a parent scroll view to display pdf.Inside that there is view.Inside that view there is another scroll view for zooming. And开发者_如何学JAVA inside that scroll view there is overlay view. i ne

I have a parent scroll view to display pdf.Inside that there is view.Inside that view there is another scroll view for zooming. And开发者_如何学JAVA inside that scroll view there is overlay view. i need to get touch of the overlay view. How can i get it?


Add a UIGestureRecognizer to the overlay view. Don't forget to make sure the view has the userActionEnabled property set to YES.


Make a new NSObject Class ScrollWithTouch and write following method inside .h and .m file:
Code for .h file:

@interface ScrollWithTouch : UIScrollView {
}
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event;
-(id)initWithCustomScrollView;
@end

Code for .m file:
#import "ScrollWithTouch.h"


@implementation ScrollWithTouch

-(id)initWithCustomScrollView{
    if (self = [super init]) {

    }
    return self;
}


- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event 
{   
    // If not dragging, send event to next responder
    if (!self.dragging) 
        [self.nextResponder touchesEnded: touches withEvent:event]; 
    else
        [super touchesEnded: touches withEvent: event];
}
@end

Now make a instance : 
ScrollWithTouch *tmpScrollView;
tmpScrollView = [[ScrollWithTouch alloc] initWithCustomScrollView];

Add this new created object with your self.view;
Now write touch related method within self.view.
Assign tag for scroll view or assign tag for sub views on scroll view.
Now you are ready to getting touch tag on tapping over scroll view.  
0

精彩评论

暂无评论...
验证码 换一张
取 消