如何检测触摸UIviewController
for a UIView
仅使用代码(没有 Interface Builder)?
我找到了 TouchBegan 方法,但它从未被调用过。我没有初始化有关此方法的任何其他内容。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
#import "TouchView.h"
//TouchView.h
#import <Foundation/Foundation.h>
#import "TouchViewDelegate.h"
@interface TouchView : UIView {
id <TouchViewDelegate> delegate;
}
@property (retain) id delegate;
@end
//TouchView.m
@implementation TouchView
@synthesize delegate;
-(id) initWithFrame:(CGRect)frame
{
self.userInteractionEnabled = YES;
return self;
}
-(id) initWithCoder:(NSCoder *)aDecoder
{
self.userInteractionEnabled = YES;
return self;
}
-(void) awakeFromNib
{
self.userInteractionEnabled = YES;
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[delegate touchDown:self];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[delegate touchUp:self];
}
@end
//TouchViewDelegate.h
#import <UIKit/UIKit.h>
@protocol TouchViewDelegate
-(void) touchDown:(id) sender;
-(void) touchUp:(id)sender;
@end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)