tags:

views:

157

answers:

1

I am having an issue with using a shake gesture with modal view switching. The shake gesture works when I move into the specified view controller the first time. When I exit and return however, it does not. I have implemented the can become first responder and viewdidAppear techniques, and the console detects a shake using an NSLog entry, but nothing happens. Everything else seems to work but it won't initiate the actions of a shake on second viewing.

Any help or insight would be greatly appreciated

A: 

please let me know what other pieces of code would be helpful -

-(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];}
Sean Tucker