我已将UIImageView添加到UIScrollView中。您可以点击滚动视图,并将另一个UIImageView添加到" main"的UIImageView。我使用此代码从触摸中获取坐标并将其转换为本地坐标:
- (void)tapped:(UITapGestureRecognizer *)gestureRecognizer {
CGPoint position = [gestureRecognizer locationInView:_imagescrollview];
CGPoint positioninimageview = [_imagescrollview convertPoint:position toView:_editimageview];
newimageview.frame = CGRectMake(positioninimageview.x, positioninimageview.y,160.f,160.f);
[self.editimageview addSubview:newimageview];
}
这有效!
我使用此代码来旋转和缩放UIImageView:
- (void)applyTransform {
CGAffineTransform rotatetransform = CGAffineTransformMakeRotation(_rotation);
CGAffineTransform scaletransform = CGAffineTransformMakeScale(_scale, _scale);
newimageview.transform = CGAffineTransformConcat(rotatetransform,scaletransform);
}
这也有效!
我使用此代码移动UIImageView:
- (void)setEyePositionAndReposition:(CGPoint)eyeposition {
CGAffineTransform t = newuiimageview.transform;
newuiimageview.transform = CGAffineTransformIdentity;
newuiimageview.frame = CGRectMake(eyeposition.x, eyeposition.y, _eyeimageview.frame.size.width, _eyeimageview.frame.size.height);
newuiimageview.transform = t;
}
这只有在眼睛不旋转和/或缩放时才有效。如果旋转为90,180,270,360等度,并且刻度为1.f则没有问题。一旦比例增加并且我移动视图,触摸x,y和newimageview x,y就会关闭。缩放越大,差异越大。我尝试使用触摸点和变换(旋转和缩放)来计算CGPoint:
CGPoint newpoint = CGPointApplyAffineTransform(newimageposition, CGAffineTransformConcat(rotatetransform,scaletransform));
但这导致负x ...
不知怎的,我必须撤消旋转和缩放
答案 0 :(得分:0)
通过设置center
来定位视图,frame
在变换下是不变的。请勿使用其HasLaunchedOnce
。