TouchesMoved UIButton xcode 4.4 iOS 5.1.1

问题描述:

我知道这个问题似乎已经被问及答案,但我无法解决我的问题。TouchesMoved UIButton xcode 4.4 iOS 5.1.1

我想将我的观点的对象跟随手指的水平幻灯片(去上一页或下一页)

对于这一点,我使用的touchesBegan,TouchesMoved和TouchesEnded方法。

它在触摸开始于视图背景时正常工作,但在uibuttons触摸开始时不起作用。

为了解决这个问题,我已经子类,我想允许手势的uibuttons,它工作正常,当我在Xcode的3.x和4.x版的iOS我刚装了OSX颇富狮子

今天并开始使用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和4.x版的iOS),我发现这里的解决方案: Is there a way to pass touches through on the iPhone?

但它不工作了...

你能帮我?

非常感谢。

编辑:问题是使用相同的[超级倒是...]代替或更多的[self.nextResponder倒是...]

+0

你解决了吗?我面临着类似的问题。我有Fingerpaint,它可以在iOS 6上正常工作,但在我的新iPad iOS7上,它不会呈现,直到touchesEnded。 touchesBegan之后只绘制了一小部分。 – 2013-11-16 21:00:15

+0

很抱歉回答迟到,但邮件已经发送到垃圾邮件箱。 我确实解决了我的问题,但不记得我是如何编写我认为正确的答案的。 – 2014-01-16 15:18:40

前一段时间我的问题解决了,不记得如何但是我的文件存在差异,所以我会在这里写出适用的新版本。

// myUIButton.h 
#import <Foundation/Foundation.h> 

@interface myUIButton : UIButton { 
} 

@end 

// myUIButton.m 

#import "myUIButton.h" 

@implementation myUIButton 

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    NSLog(@"uibutton touches began"); 
    [super touchesBegan:touches withEvent:event]; 
    [self.nextResponder touchesBegan:touches withEvent:event]; 
} 

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    NSLog(@"uibutton touches moved"); 
    [super touchesMoved:touches withEvent:event]; 
    [self.nextResponder touchesMoved:touches withEvent:event]; 
} 

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    NSLog(@"uibutton touches ended"); 
    [super touchesEnded:touches withEvent:event]; 
    [self.nextResponder touchesEnded:touches withEvent:event]; 
} 

@end 

在每个视图中,我需要这种行为,我将在file.xib全景手势识别器,我链接到行动panRecognizer:在file.m

// file.m 

@synthesize slide_origin_x; 

-(IBAction)panRecognizer:(UIPanGestureRecognizer *)recognizer { 
    // Recording movement 
    if (recognizer.state == UIGestureRecognizerStateBegan) { 
     self.slide_origin_x = [NSNumber numberWithFloat:recognizer.view.center.x]; 
    } 

    // Choose an action 
    else if (recognizer.state == UIGestureRecognizerStateEnded) { 
     int to_launch_action = 100; // Action choosen after 100 pixels 
     int touch_move = [self.slide_origin_x intValue] - recognizer.view.center.x; 
     if (touch_move > (0 + to_launch_action)) { 
      /* 
      * What happens if the view slide to the left (eg : go_to_next) 
      */ 
     } else if (touch_move < (0 - to_launch_action)) { 
      /* 
      * What happens if the view slide to the right (eg : go_to_previous) 
      */ 
     } 
     // The view goes back to normal 
     recognizer.view.center = CGPointMake([self.slide_origin_x intValue], recognizer.view.center.y); 
    } 

    // The view is moved 
    else { 
     CGPoint translation = [recognizer translationInView:self.view]; 
     recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, 
              recognizer.view.center.y); 
     [recognizer setTranslation:CGPointMake(0,0) inView:self.view]; 
    } 
} 

FYI定义:这作品也在XCode5和SDK6.1上