<span style="font-weight: normal;">- (void)viewDidLoad
{
[super viewDidLoad];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Fav_Filter_ALL_HL"]];
imageView.frame = CGRectMake(100, 100, 100, 100);
[self.view addSubview:imageView];
/*
当前视图设为view=bigimgView.userInteractionEnabled=NO 时,当前视图不可交互,该视图上面的子视图也不可交互(不可响应),响应事件传递到下面的父视图。
当前视图设为view=bigimgView.userInteractionEnabled=YES 时,当前视图可交互,该视图上面的子视图可以交互(可以响应),下面的父视图不会接收到响应。
uiimageview 默认的userInteractionEnabled是NO;
UIView的userInteractionEnabled默认是YES。
对比enabled
uibutton.enabled=YES;//可点
uibutton.enabled=NO;//不可点
*/
self.view.userInteractionEnabled = YES;
}</span>
<span style="font-weight: normal;">- (void)viewDidLoad
{
[super viewDidLoad];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Fav_Filter_ALL_HL"]];
imageView.frame = CGRectMake(100, 100, 100, 100);
[self.view addSubview:imageView];
/*
当前视图设为view=bigimgView.userInteractionEnabled=NO 时,当前视图不可交互,该视图上面的子视图也不可交互(不可响应),响应事件传递到下面的父视图。
当前视图设为view=bigimgView.userInteractionEnabled=YES 时,当前视图可交互,该视图上面的子视图可以交互(可以响应),下面的父视图不会接收到响应。
uiimageview 默认的userInteractionEnabled是NO;
UIView的userInteractionEnabled默认是YES。
对比enabled
uibutton.enabled=YES;//可点
uibutton.enabled=NO;//不可点
*/
self.view.userInteractionEnabled = YES;
}</span>
//手指开始触摸会调用
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
//获取当前手指点击的中心坐标
CGPoint point = [touch locationInView:self.view];
//改变图片的中心坐标
imageView.center = point;
//NSLog(@"%@",NSStringFromCGPoint(point));
}
//手指在屏幕上移动会调用
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
UITouch *touch = [touches anyObject];
//获取当前手指点击的中心坐标
CGPoint point = [touch locationInView:self.view];
//改变图片的中心坐标
imageView.center = point;
//NSLog(@"touchesMoved");
}
//手指离开屏幕会调用
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];
NSLog(@"touchesEnded");
}