我知道这个问题似乎已经被问及并得到了回答,但我无法解决我的问题。
我想移动视图中的对象以跟随手指的水平滑动(转到上一页或下一页)
为此,我使用了 TouchesBegan、TouchesMoved 和 TouchesEnded 方法。
当在视图背景上开始触摸时它工作正常,但在 uibutton 上开始触摸时不起作用。
为了解决这个问题,我对我想要允许手势的 uibuttons 进行了子类化,当我在 xCode 3.x 和 iOS 4.x 上时它工作正常
今天我刚刚安装了 OSX Moutain Lion 并开始在 xCode 4.4 和 iOS 5.1.1 (iPAD) 上工作。在这里,我使用的是同样运行良好但不再工作的应用程序。
这是我的 UIButton 子类:
// myUIButton.h
#import <UIKit/UIKit.h>
@interface myUIButton : UIButton
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
@end
// myUIButton.m
#import "myUIButton.h"
@implementation myUIButton
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"uibutton touches began");
[self.nextResponder touchesBegan:touches withEvent:event];
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"uibutton touches moved");
[self.nextResponder touchesMoved:touches withEvent:event];
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"uibutton touches ended");
[self.nextResponder touchesEnded:touches withEvent:event];
}
@end
以下是我的主类中的方法:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"view touches began");
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"view touches moved");
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"view touches ended");
}
当我在 UIButton 上开始触摸时,我从子类中获取每个 NSLog,但主要的 touchesMoved 只执行一次。(self.nextResponder 似乎只工作一次)
有什么改变使它不能在 xcode 4.4 或 iOS 5.1.1 上运行吗?
当我第一次尝试这样做时(在 xcode 3.x 和 iOS 4.x 上),我在这里找到了解决方案: 有没有办法在 iPhone 上传递触摸?
但它不再起作用了......
你可以帮帮我吗?
非常感谢。
编辑:使用 [super touches...] 代替或更多 [self.nextResponder touches...] 的问题是相同的