gpt4 book ai didi

iphone - 双击缩放 UIImageView

转载 作者:行者123 更新时间:2023-12-03 19:30:30 26 4
gpt4 key购买 nike

我正在查看 Apple 的 ScrollViewSuite 示例代码。相比之下,我一定做错了什么。在他们的 RootViewController 中,他们这样做:

- (void)loadView {
[super loadView];

// set the tag for the image view
[imageView setTag:ZOOM_VIEW_TAG];

// add gesture recognizers to the image view
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];

[doubleTap setNumberOfTapsRequired:2];
[twoFingerTap setNumberOfTouchesRequired:2];

[imageView addGestureRecognizer:singleTap];
[imageView addGestureRecognizer:doubleTap];
[imageView addGestureRecognizer:twoFingerTap];

[singleTap release];
[doubleTap release];
[twoFingerTap release];

// calculate minimum scale to perfectly fit image width, and begin at that scale
float minimumScale = [imageScrollView frame].size.width / [imageView frame].size.width;
[imageScrollView setMinimumZoomScale:minimumScale];
[imageScrollView setZoomScale:minimumScale];
}

在 IB 中,他们将 imageView 作为 imageScrollView 的 subview 。我的 .xib 的设置方式相同。我将此代码放在 viewDidLoad 而不是 loadView 中。当我双击 imageView 时,我没有接到任何电话。我想知道为什么。这是我对他们所做的事情的版本:

- (void)viewDidLoad {
[self updateOnScreenImages]; // this is where my imageView.image property gets set

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
doubleTap.numberOfTapsRequired = 2;

UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];
[doubleTap setNumberOfTouchesRequired:2];


[self.imageView addGestureRecognizer:doubleTap];
[self.imageView addGestureRecognizer:twoFingerTap];

[doubleTap release];
[twoFingerTap release];

}

与 Apple 所做的相比,我做的有什么问题吗?这个逻辑似乎和我很相似。但是当我双击时我没有收到回调。我也尝试将手势添加到 self.scrollView 中,但这也不起作用。想法?谢谢!

最佳答案

尝试添加:

   self.imageView.userInteractionEnabled = YES;

默认情况下,UIImageView将该属性设置为NO
(苹果可能已经在 XIB 文件中更改了它,并且您可能已经丢失了...)

关于iphone - 双击缩放 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12568765/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com