我有一个应用程序,我的主视图同时接受 touchesBegan
和 touchesMoved
,因此接受单指触摸和拖动。我想实现一个 UIScrollView
,我让它工作,但它覆盖了拖动,因此我的 contentView 永远不会收到它们。我想实现一个 UIScrollview
,其中两指拖动表示滚动,而单指拖动事件会传递给我的内容 View ,因此它可以正常执行。我需要创建自己的 UIScrollView
子类吗?
这是我实现 UIScrollView
的 appDelegate
中的代码。
@implementation MusicGridAppDelegate
@synthesize window;
@synthesize viewController;
@synthesize scrollView;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
//[application setStatusBarHidden:YES animated:NO];
//[window addSubview:viewController.view];
scrollView.contentSize = CGSizeMake(720, 480);
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.showsVerticalScrollIndicator = YES;
scrollView.delegate = self;
[scrollView addSubview:viewController.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[viewController release];
[scrollView release];
[window release];
[super dealloc];
}
最佳答案
在 SDK 3.2 中,UIScrollView 的触摸处理是使用手势识别器处理的。
如果要进行两指平移而不是默认的单指平移,可以使用以下代码:
for (UIGestureRecognizer *gestureRecognizer in scrollView.gestureRecognizers) {
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
UIPanGestureRecognizer *panGR = (UIPanGestureRecognizer *) gestureRecognizer;
panGR.minimumNumberOfTouches = 2;
}
}
关于iphone - 使用 UIScrollView 用两根手指滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/787212/