UITapGestureRecognizer在iPad上启动但在iPhone上没有,但它是相同的代码

时间:2013-03-11 20:07:55

标签: ios uitapgesturerecognizer

我有一个小问题,不应该...... 我正在制作适用于iOS的通用应用程序,而我在使用iPad时触发的UITapGestureRecognizer有问题但在iPhone上没有。

更新开始

我在iPad上强制使用iPad笔尖,它可以正常工作!所以我的iPhone nib文件有问题,因为两个nib只包含一个UIView和UIScrollView,因为使用代码放置其他任何东西可能会出错......

更新结束

为UIView子类添加了我的识别器:

h file:

#import <UIKit/UIKit.h>

@interface POI : UIView <UIGestureRecognizerDelegate>{
    UIImageView *pointBgView;
    float tipHeight;
    float tipWidth;
}
-(id)initWithPointBg:(NSString *)pointBgURL andFrame:(CGRect)frame;
@property (nonatomic) float tipHeight;
@property (nonatomic) float tipWidth;
@end

m file:

#import "POI.h"
#import <QuartzCore/QuartzCore.h>

@implementation POI

@synthesize tipHeight,tipWidth;

-(id)initWithPointBg:(NSString *)pointBgURL andFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UITapGestureRecognizer *tapRecognizer =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(respondToTap:)];
        // Specify that the gesture must be a single tap
        tapRecognizer.numberOfTapsRequired = 1;
        [tapRecognizer setDelegate:self];
        // Add the tap gesture recognizer to the view
        [self addGestureRecognizer:tapRecognizer];

        pointBgView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:pointBgURL]];
        pointBgView.layer.shadowColor = [[UIColor blackColor] CGColor];
        pointBgView.layer.shadowOpacity = 0.7;
        pointBgView.layer.shadowRadius = 4.0;
        pointBgView.clipsToBounds = NO;
        pointBgView.userInteractionEnabled = YES;

        pointBgView.layer.shadowOffset = CGSizeMake(0, 0);
        pointBgView.layer.shadowPath = [UIBezierPath bezierPathWithRect:pointBgView.bounds].CGPath;

        [pointBgView.layer setBorderColor: [[UIColor whiteColor] CGColor]];
        [pointBgView.layer setBorderWidth: 2.0];



        [self addSubview:pointBgView];
        [self setBackgroundColor:[UIColor clearColor]];
        self.tipHeight = 30;
        self.tipWidth = 50;



    }
    return self;

}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 
{
    NSLog(@"TAP");
    return YES;
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    NSLog(@"StartTap");
    return YES;
}

-(void)respondToTap:(UITapGestureRecognizer *)recognizer
{
    NSLog(@"UITAP");
    [[NSNotificationCenter defaultCenter]
 postNotificationName:@"POITap"
 object:self];

}

以上是有问题的代码......

在iPad上进行测试时会触发所有NSLog,但不会在iPhone(模拟器或非模拟器)上进行测试。

所以:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 

没有解雇......

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    NSLog(@"StartTap");
    return YES;
}

没有解雇......

-(void)respondToTap:(UITapGestureRecognizer *)recognizer
{
    NSLog(@"UITAP");
    [[NSNotificationCenter defaultCenter]
 postNotificationName:@"POITap"
 object:self];

}

......没有开火!?

我必须说这是为这个应用程序使用两个单独的笔尖(显然一个用于iPad,另一个用于iPhone),并且两者在它们包含的内容方面完全相同...

我添加了代表,因为它不适用于iPhone,所以我想看看它是否有用,没有运气...

世界上可能出现这种行为的原因是什么?

感谢您提供任何帮助&amp;和平你可以带给我:)。

干杯!

1 个答案:

答案 0 :(得分:0)

看起来它是UIScrollView的一个问题,即使在iPad上我也无法点击一个imageView,如果它在滚动视图出现时不可见(在UIScrollView的可见帧之外)。

至少我知道我并不疯狂:)

由于