gpt4 book ai didi

ios - 如何在 iOS 中点击缩放和双击缩小?

转载 作者:IT王子 更新时间:2023-10-29 08:05:10 24 4
gpt4 key购买 nike

我正在开发一个应用程序以使用 UIScrollView 显示 UIImages 的画廊,我的问题是,如何点击以缩放并双击以缩小,在使用UIScrollView 处理时它是如何工作的。

最佳答案

您需要实现 UITapGestureRecognizer - 文档 here - 在你的 View Controller 中

- (void)viewDidLoad
{
[super viewDidLoad];

// what object is going to handle the gesture when it gets recognised ?
// the argument for tap is the gesture that caused this message to be sent
UITapGestureRecognizer *tapOnce = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnce:)];
UITapGestureRecognizer *tapTwice = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwice:)];

// set number of taps required
tapOnce.numberOfTapsRequired = 1;
tapTwice.numberOfTapsRequired = 2;

// stops tapOnce from overriding tapTwice
[tapOnce requireGestureRecognizerToFail:tapTwice];

// now add the gesture recogniser to a view
// this will be the view that recognises the gesture
[self.view addGestureRecognizer:tapOnce];
[self.view addGestureRecognizer:tapTwice];

}

基本上这段代码是说,当 UITapGestureself.view 中注册时,方法 tapOncetapTwice 将在 self 中调用,具体取决于它是单击还是双击。因此,您需要将这些点击方法添加到您的 UIViewController:

- (void)tapOnce:(UIGestureRecognizer *)gesture
{
//on a single tap, call zoomToRect in UIScrollView
[self.myScrollView zoomToRect:rectToZoomInTo animated:NO];
}
- (void)tapTwice:(UIGestureRecognizer *)gesture
{
//on a double tap, call zoomToRect in UIScrollView
[self.myScrollView zoomToRect:rectToZoomOutTo animated:NO];
}

希望对你有帮助

关于ios - 如何在 iOS 中点击缩放和双击缩小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9008975/

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