この SO-answerで説明されているようUITapGestureRecognizer
に、のサブクラスに実装しようとしていUIIMageView
ます。私のアプローチは以下にあります。
のインスタンスMenuButtonImageView
は のサブビューですhomeScreenViewController.view
。
も実装しましたがtouchesBegan:withEvent:
、うまく動作します。touchesMoved:withEvent:
touchesEnded:withEvent:
問題: どういうわけかhandleSingleFingeredTap:
呼び出されません。これには何が問題になる可能性がありますか?
@interface MenuButtonImageView : UIImageView
@property (nonatomic, weak) IBOutlet HomescreenViewController *homeScreenViewController;
@property (nonatomic, readwrite) Visibility visibility;
- (void)handleSingleFingeredTap:(UITapGestureRecognizer *)recognizer;
@end
@implementation MenuButtonImageView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.visibility = HIDDEN;
self.userInteractionEnabled = YES;
UITapGestureRecognizer * singleFingeredTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleFingeredTap:)];
singleFingeredTap.numberOfTapsRequired = 1;
[self addGestureRecognizer:singleFingeredTap];
}
return self;
}
- (void)handleSingleFingeredTap:(UITapGestureRecognizer *)recognizer {
NSLog(@"handleTap was called"); // This method is not called!
[self toggleMainMenu];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { ... }
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { ... }
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { ... }
@end