当我缩放imageview,然后点击图像图像关闭ios

时间:2014-05-05 13:51:14

标签: ios objective-c uigesturerecognizer

注意:这是我将此手势添加到我的imageview

的方式
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];
    pinchGesture.delegate=self;
    [self.editPictureImageView  addGestureRecognizer:pinchGesture];

注意:这是我处理夹点转换的方法 mcurrentscale和mlastscale属于浮点型

-(void)handlePinch:(UIPinchGestureRecognizer*)sender {

    mCurrentScale += [sender scale] - mLastScale;
    mLastScale = [sender scale];

    if (sender.state == UIGestureRecognizerStateEnded)
    {
        mLastScale = 1.0;
    }

    if (mCurrentScale < 1)
    {
        mCurrentScale = 1.0;
    }

    CGAffineTransform currentTransform = CGAffineTransformIdentity;

    CGAffineTransform newTransform = CGAffineTransformScale(currentTransform,    mCurrentScale, mCurrentScale);
    self.editPictureImageView.transform = newTransform;


}

plzz帮助

1 个答案:

答案 0 :(得分:0)

这可能是一种更尴尬的方式。

我会重新考虑你的方法:

UIImageView添加到UIScrollView。 imageView的框架应该是scrollView的边界,我的意思是在它的默认位置,imageView应该像在坐在普通视图中一样坐在scrollView中。

设置UIScrollView(IB或代码):

self.scrollView.delegate = self;
//    example values
self.scrollView.minimumZoomScale = 0.4f;
self.scrolLView.maximumZoomScale = 3.0f;

采用这种方法:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    //  allow zooming of our image view
    return self.imageView;
}