我在使用具有模态视图切换的摇动手势时遇到问题。第一次进入指定的视图控制器时,摇动手势有效。然而,当我退出并返回时,它没有。我已经实现了can成为第一响应者和viewdidAppear技术,并且控制台使用NSLog条目检测到抖动,但没有任何反应。其他一切似乎都有效,但它不会在第二次观看时发起动摇。
非常感谢任何帮助或见解
答案 0 :(得分:0)
请告诉我其他哪些代码会有所帮助 -
-(BOOL)canBecomeFirstResponder {
return YES;}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if ( event.subtype == UIEventSubtypeMotionShake )
{
// Put in code here to handle shake
NSLog(@"Shaken");
time = 9.0;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countdown) userInfo:nil repeats:NO];
myAnimatedView.hidden = NO;
myAnimatedView2.hidden = NO;
myAnimatedView3.hidden = NO;
webViewRandomizer.hidden = YES;
backToRandomizer.hidden = YES;
backToRandomizerBG.hidden = YES;
backRandomizer.hidden = YES;
forwardRandomizer.hidden = YES;
backToRandomizerMenu.hidden = YES;
tweetView.image = [UIImage imageNamed:@"3988567990_60d8da5cdf_o.jpg"];
[webViewRandomizer resignFirstResponder];
[self becomeFirstResponder];
[myAnimatedView setAnimationRepeatCount:6];
[myAnimatedView2 setAnimationRepeatCount:2];
[myAnimatedView3 setAnimationRepeatCount:1];
myAnimatedView.animationDuration = 0.5;
myAnimatedView2.animationDuration = 3.0;
myAnimatedView3.animationDuration = 9.0;
[myAnimatedView startAnimating];
[myAnimatedView2 startAnimating];
[myAnimatedView3 startAnimating];
NSURL *url = [NSURL URLWithString:@"http://historicaltweets.com/"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webViewRandomizer loadRequest:requestObj];
[self performSelector:@selector(aShowRandomizer) withObject:nil afterDelay:10.0f];}
if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] ){
[super motionEnded:motion withEvent:event]; }}
#define kUpdateInterval (1.0f/60.0f)
- (void)viewDidAppear:(BOOL)animated{
UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
accel.delegate = self;
accel.updateInterval = kUpdateInterval;
[super viewDidAppear:animated];
[self becomeFirstResponder];}
- (void)viewDidDisappear:(BOOL)animated{
UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
accel.delegate = nil;}
-(IBAction)backToRandomizerMenuGo{
[self dismissModalViewControllerAnimated:YES];}