我是iOS新手,需要满足以下需求。请给我一些指导如何做到这一点。谢谢!
我知道如何使用CGImageCreateWithMask以及如何将uiimageview放在scrollview中以进行缩放。但我不知道如何将它们组合在一起并进行自定义控制。
答案 0 :(得分:0)
要旋转图像,您可以使用UIPanGestureRecognizer并放大/缩小您可以使用UIPinchGestureRecognizer。可能是下面的代码可以帮助你。
// In your vieDidLoad use:
UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panned:)];
UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinched:)];
[self.imageview addGestureRecognizer:pinch];
[self.imageview addGestureRecognizer:pan];
and add the selector methods:
// To zoom in/out
- (void)pinched:(UIPinchGestureRecognizer *)sender {
if (sender.scale >1.0f && sender.scale < 2.5f) {
CGAffineTransform transform = CGAffineTransformMakeScale(sender.scale, sender.scale);
imageview.transform = transform;
}
}
//To rotate
-(void) panned:(UIGestureRecognizer *)gesture
{
CGPoint translatedPoint = [(UIPanGestureRecognizer*)gesture translationInView:imageview];
if([(UIPanGestureRecognizer*)gesture state] == UIGestureRecognizerStateBegan) {
_firstX = [imageview center].x;
_firstY = [imageview center].y;
}
translatedPoint = CGPointMake(_firstX+translatedPoint.x, _firstY+translatedPoint.y);
[imageview setCenter:translatedPoint];
}
在viewDidLoad中你还应该将你的框架作为子视图添加到imageview。
答案 1 :(得分:0)
这两个链接都可以帮助您100%。
http://code4app.net/ios/scale-an-image-by-pinch/507e21c36803fa4667000000
http://code4app.net/ios/Image-Cropper/4f8cc87f06f6e7d86c000000
答案 2 :(得分:0)
您还可以将帧图像放在执行缩放的scrollView上,作为子视图。这样,两个图像都应该放大。