我正在尝试在UIImageView上应用手势,当我给手势设置动作时,图像视图中的缩放、旋转和移动都可以工作。因此,我可以看到图像从一个点旋转、缩放并移动到另一个点。
当我将图像缩小并将缩放级别设置为最小值时,触摸UIView(UIImageView的超类)时也给出了手势操作。如何限制仅在UIImageView而不是UIView上有效的手势操作?并且正在尝试将其限制在UIVIew内,以使Imageview不会超出视图之外。
当我将图像缩小并将缩放级别设置为最小值时,触摸UIView(UIImageView的超类)时也给出了手势操作。如何限制仅在UIImageView而不是UIView上有效的手势操作?并且正在尝试将其限制在UIVIew内,以使Imageview不会超出视图之外。
-(void)InitGestures{
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
tapRecognizer.numberOfTouchesRequired = 1;
templatePhotoPlaceholderView=[[UIView alloc]init];
templatePhotoPlaceholderView.clipsToBounds = YES;
//templatephotoplaceholder frame setting
[self templatePhotoPlaceholderFrameSetting];
templatePhotoPlaceholderView.backgroundColor=[UIColor colorWithRed:0.8823 green:0.8823 blue:0.8823 alpha:1];
[self photoView:templatePhotoPlaceholderView];
tapRecognizer.view.frame=templatePhotoPlaceholderView.frame;
[self photoButtonPlaceHolder:templatePhotoPlaceholderView];
[selectedTemplateImage addSubview:templatePhotoPlaceholderView];
[templatePhotoPlaceholderView addGestureRecognizer:tapRecognizer];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[templatePhotoPlaceholderView addGestureRecognizer:panRecognizer];
//[panRecognizer release];
UIPinchGestureRecognizer *pinchRecognizer = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)] autorelease];
[pinchRecognizer setDelegate:self];
[self.view addGestureRecognizer:pinchRecognizer];
//[pinchRecognizer release];
[self.view addSubview:templatePhotoPlaceholderView];
[tapRecognizer release];
}
-(void)move:(UIPanGestureRecognizer *)gestureRecognizer
{
CGPoint translatedPoint = [gestureRecognizer translationInView:templatePhotoPlaceholderView];
if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
_firstX = [imageview center].x;
_firstY = [imageview center].y;
}
translatedPoint = CGPointMake(_firstX+translatedPoint.x, _firstY+translatedPoint.y);
[imageview setCenter:translatedPoint];
}