0
我在視圖中添加了一個UIView
(「盒子」),我想在它中檢測觸摸。如何檢測我觸摸特定區域?
我在谷歌搜索和這個網站,並找到很多答案,但我想,當上箱視圖(僅中查看)觸摸顯示我在控制檯NSLog("1")
,當我的看法觸摸除了箱的地方(在對方出的盒子查看我的控制檯演示我NSLog("2")
)
我很困惑,請幫助我。這是我的代碼:
@interface RootViewController : UIViewController
@property (nonatomic,strong) UIView *Box;
@end
@implementation RootViewController
@synthesize window,Box;
- (void)viewDidLoad
{
[super viewDidLoad];
Box = [[UIView alloc] initWithFrame:CGRectMake(53.0, 100.0, 214, 124)];
[Box setBackgroundColor:[UIColor greenColor]];
[self.view addSubview:Box];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint locationPoint = [[touches anyObject] locationInView:self.view];
}
感謝我的朋友:d – user3599133