iphone - UIPinchGestureRecognizer 和 UIImageView 的问题

标签 iphone objective-c ios ipad

我正在尝试通过 UIPinchGestureRecognizer 捏图像,但是问题是我的代码无法正常工作,实际上它无法缩放我的图像

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

    CGAffineTransform myTransformation =
    CGAffineTransformMakeScale(sender.scale, sender.scale);
    sender.view.transform = myTransformation;
}


- (void)viewDidLoad
{
  UIPinchGestureRecognizer *pinch =
    [[UIPinchGestureRecognizer alloc]
     initWithTarget:self
     action:@selector(pinching:)];

    pinch.delegate = self;

    [imageBG addGestureRecognizer:pinch];

    [imageBG setUserInteractionEnabled:YES];
    [imageBG setMultipleTouchEnabled:YES];
}

最佳答案

尝试使用UIScrollView

为此,请创建它

self.scrollView = [[UIScrollView alloc] initWithFrame:...];
self.scrollView.delegate = self;
self.scrollView.maximumZoomScale = 2.0; // adjust as you need
self.scrollView.minimumZoomScale = 0.5; // adjust as you need
[self.scrollView addSubview:self.imageView];

并添加委托(delegate)方法:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return self.imageView;
}

关于iphone - UIPinchGestureRecognizer 和 UIImageView 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14021669/

相关文章:

Objective-C:制作文档

ios - 从 Facebook 解析 Json

ios - @compatibility_alias 和 typedef 在 Objective-C 中的 @class 上使用有什么区别

ios - 如何正确地将弱引用传递给函数的调用者?

ios - UIWebview 在当前文本字段上设置文本

ios - sysctlbyname错误函数 'sysctlbyname'的隐式声明在C99中无效

ios - 使用 Google-Maps-iOS-SDK (1.8.1) 时架构 armv7 的 undefined symbol

ios - Alamofire 单例 webservercall 类错误

iPhone - 如何将导航 Controller 添加到 View ?

ios - 了解我的应用程序是否从应用程序商店更新