【发布时间】:2012-08-03 15:28:32
【问题描述】:
我知道这个问题似乎已经被问及并得到了回答,但我无法解决我的问题。
我想移动视图中的对象以跟随手指的水平滑动(转到上一页或下一页)
为此,我使用了 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 上),我在这里找到了解决方案: Is there a way to pass touches through on the iPhone?
但它不再起作用了......
你能帮帮我吗?
非常感谢。
编辑:使用 [super touches...] 代替或在更多 [self.nextResponder touches...] 中问题是相同的
【问题讨论】:
-
你解决了吗?我面临着类似的问题。我有 Fingerpaint,它在 iOS 6 上运行良好,但在我的新 iPad iOS7 上,直到 touchesEnded 才会呈现。 touchesBegan 后只画了一小部分
-
很抱歉这么晚才回复,但邮件已进入垃圾邮件箱。我确实解决了我的问题,但不记得具体是如何解决的,所以我写了我认为正确的答案。
标签: objective-c uibutton touchesmoved