我知道这个问题似乎已经被提出和回答,但我无法解决我的问题。
我想移动视图中的对象以跟随手指的水平滑动(转到上一页或下一页)
为此,我使用 TouchesBegan、TouchesMoved 和 TouchesEnded 方法。
当触摸开始于视图背景时它工作正常,但当触摸开始于 uibuttons 时则不起作用。
为了解决这个问题,我对我想要允许手势的 uibuttons 进行了子类化,当我在 xCode 3.x 和 iOS 4.x 上时它工作正常
今天我刚刚安装了 OS X Mountain 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,但主要的 TouchMoved 仅执行一次。 (self.nextResponder 似乎只工作一次)
是否发生了某些变化导致它无法在 xcode 4.4 或 iOS 5.1.1 上运行?
当我第一次尝试这样做时(在 xcode 3.x 和 iOS 4.x 上),我在这里找到了解决方案:有没有办法在 iPhone 上传递触摸? https://stackoverflow.com/questions/631427/is-there-a-way-to-pass-touches-through-on-the-iphone
但它不再起作用了......
你可以帮帮我吗?
多谢。
编辑:问题与使用 [super Touchs...] 代替或在更多 [self.nextResponder Touchs...] 中是相同的