ios- zoom and rotate a masked UIImageView [closed]

你离开我真会死。 提交于 2019-12-08 09:07:35

问题


I'm new to iOS and need to have the needs below. Please give me some directions on how to do this. Thanks!

  • Have an image(source) masked by another image (frame)
  • User can drag,zoom, rotate the source image. The frame image keeps still.

I know how to use CGImageCreateWithMask and how to put uiimageview inside a scrollview for pinch to zoom. But I don't know how to combine these together and make a custom control.


回答1:


To rotate an image you can use UIPanGestureRecognizer and to zoom in/out you can use UIPinchGestureRecognizer. May be the code below could help you.

// 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];

    }

in your viewDidLoad your should also add your frame as as subview to the imageview.




回答2:


These both links will help you 100%.

http://code4app.net/ios/scale-an-image-by-pinch/507e21c36803fa4667000000

http://code4app.net/ios/Image-Cropper/4f8cc87f06f6e7d86c000000




回答3:


You could also put the frame image onto the scrollView that does the zooming, as a subview. That way, both images should zoom together.



来源:https://stackoverflow.com/questions/21586331/ios-zoom-and-rotate-a-masked-uiimageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!