我在UIImageView上檢測觸摸事件時遇到問題。我有子歸類的UIImageView和overrided canBecomeFirstResponder,touchedBegan和touchesEnded:在iOS 5中UIImageView上觸摸事件的問題
@implementation ImageViewNext
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.userInteractionEnabled = YES;
}
return self;
}
-(BOOL)canBecomeFirstResponder
{
return YES;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Touches Began event");
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Touches Ended");
}
我要確保所有家長的意見有用戶交互啓用。
但我沒有得到我的活動?
我試圖在這裏找到解決方案,但沒有任何運氣。但在我的搜索中,我發現有些人使用「UIGestureRecognizer」來獲得相同的效果。因此,作爲一個側面問題,什麼是「正確的」解決方案使用覆蓋方法或使用UIGestureRecognizer?我不喜歡解決方案,一個正常的按鈕被給予一個圖像,所以請保持那些帖子:)
你是對的initWithFrame:不叫!謝謝這是解決我的問題:) – DNRN