[英]Why isn't my tap recognised?
我創建了一個小示例項目,其中包含一個包含圖像視圖的筆尖。 在視圖控制器代碼中,我向圖像視圖添加了手勢識別器以檢測輕擊。 但是它從不調用處理程序方法。
這是標題:
#import <UIKit/UIKit.h>
@interface TapExperimentViewController : UIViewController {
UIImageView *imageView;
}
@property (retain) IBOutlet UIImageView *imageView;
- (void)handleTap:(UIGestureRecognizer *)sender;
@end
這是實現文件:
#import "TapExperimentViewController.h"
@implementation TapExperimentViewController
@synthesize imageView;
- (void)dealloc {
[imageView release];
[super dealloc];
}
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleTap:)];
[self.imageView addGestureRecognizer:tap];
[tap release];
}
- (void)viewDidUnload {
[super viewDidUnload];
self.imageView = nil;
}
- (void)handleTap:(UIGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"tap");
}
}
@end
我確保插座已連接。 為什么在我觸摸圖像時不調用handleTap :?
我自己沒有使用手勢,但是我知道UIImageView
默認情況下不啟用用戶交互。
默認情況下,新的圖像視圖對象配置為忽略用戶事件。 如果要處理UIImageView的自定義子類中的事件,則必須在初始化對象后將userInteractionEnabled屬性的值顯式更改為YES。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.