0

我有一个不应该的小问题......我正在为 iOS 制作一个通用应用程序,但我遇到了在 iPad 上触发但在 iPhone 上没有触发的 UITapGestureRecognizer 问题。

更新开始

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

更新结束

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

h 文件:

#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 文件:

#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 上运行,所以我想看看它是否有帮助,没有运气......

到底是什么原因导致了这种行为?

感谢您能给我带来的任何帮助与和平:)

干杯!

4

1 回答 1

0

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

至少我知道我没疯:)

谢谢

于 2013-03-18T15:20:10.327 回答