开发者

How to enable touch began in UIScrollView?

Am using UIScrollview, when开发者_C百科 i am trying to capture touch event in UIscrollview is not responding. how should i achieve it? i am using UILable for showing the text.


Yes I was also facing the same problem.But finally I got remedy on it. Solution is that you will have to create a class inherited from UIScrollview as follows:

#import <Foundation/Foundation.h>
@interface CustomScrollView : UIScrollView 
{

}

@end

And override the touches method in its implementation file as follows:

#import "CustomScrollView.h"


@implementation CustomScrollView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.nextResponder touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    if(!self.dragging){
        [self.nextResponder touchesMoved:touches withEvent:event];
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.nextResponder touchesEnded:touches withEvent:event];
}

@end

You will have to import this class in the required file and use its object instead of UIScrollview"s object. Now you can see that control reaches to touches methods in the class in which you have added scrollview whenever you touch on it.

Thanks.


As of iOS 3.2 UIScrollView does not listen to touchesBegan:, touchesMoved:, touchesEnded:, etc. anymore, afaik.

You should add Gesture Recognizers instead to handle touch events in your UIScrollView. http://developer.apple.com/iphone/library/documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html

But if you want to handle the touches in one of the UIScrollView's subviews, it would be best to read the Overview section in the UIScrollView documentation. See touchesShouldBegin:withEvent:inContentView:, pagingEnabled, and delaysContentTouches, among others. http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html


"split" writes about a solution here that I used in my project to be able to access touches in a scroll view.


No need to go anywhere simple solution is here. Really as simple as you think.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜