你好,
我有一个在屏幕上有三个 UIScrollViews 的视图。每当用户摇动 iPhone 时,我想将 UIScrollViews 随机滚动到不同的位置,但我无法完成它。
我在我的 ViewController 类中实现了以下内容来检测和处理摇动手势,这 3 个 UIScrollViews 也属于同一个类。检测到摇晃手势,但 UIScrollViews 没有改变。我究竟做错了什么??
我已经尝试过motionBegan和motionEnded。
-(BOOL)canBecomeFirstResponder {
return YES;
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
[self resignFirstResponder];
[super viewWillDisappear:animated];
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake)
{
int randomTag = arc4random() % [dirContents count];
CGRect nextImageView = [[scrollView1 viewWithTag:2] frame];
[scrollView1 scrollRectToVisible:nextImageView animated:YES];
randomTag = arc4random() % [dirContents count];
nextImageView = [[scrollView2 viewWithTag:4] frame];
[scrollView2 scrollRectToVisible:nextImageView animated:YES];
randomTag = arc4random() % [dirContents count];
nextImageView = [[scrollView3 viewWithTag:4] frame];
[scrollView3 scrollRectToVisible:nextImageView animated:YES];
NSLog(@"Shake Detected End");
}
}
谢谢你