加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何检测用户是否在iOS编程中没有捏合和缩放

发布时间:2020-12-14 17:31:38 所属栏目:百科 来源:网络整理
导读:Hello Devs(这是我在Stack-Overflow中的第一篇文章,所以请在评论中告诉我我做错了:). 此代码检测用户是否正在捏合: UIPinchGestureRecognizer *twoFingerPinch = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:
Hello Devs(这是我在Stack-Overflow中的第一篇文章,所以请在评论中告诉我我做错了:).

此代码检测用户是否正在捏合:

UIPinchGestureRecognizer *twoFingerPinch = 
  [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)] autorelease];
[[self view] addGestureRecognizer:twoFingerPinch];

虚空行动:

- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer 
{
  NSLog(@"Pinch scale: %f",recognizer.scale);
}

问题是我想检测用户是否在20秒内没有收缩,因此我可以提醒用户@“捏合以显示更多图像”.我正在使用图像缩略图,如果用户捏它将显示更多图像.感谢您的帮助,祝您度过愉快的假期.

解决方法

使用20秒启动计时器,当用户捏时,仅在twoFingerPinch方法中无效.无论何时需要开始检查,都要启动此计时器.在计时器操作方法中,您可以输入代码以显示此警报.

在.h文件中声明计时器,

@property(nonatomic,strong) NSTimer *timer;

在viewDidLoad或你想要启动计时器检查这个的任何方法,

self.timer = [NSTimer scheduledTimerWithTimeInterval:20.0f target:self selector:@selector(showAlert) userInfo:nil repeats:YES];

在showAlert方法中,

- (void)showAlert {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Pinch to show more Images" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil];
    [alert show];
}

在twoFingerPinch方法中,

- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer 
{
  NSLog(@"Pinch scale: %f",recognizer.scale);
  [self.timer invalidate];

  //if the timer needs to be restarted add,self.timer = [NSTimer scheduledTimerWithTimeInterval:20.0f target:self selector:@selector(showAlert) userInfo:nil repeats:YES];
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读