2011-08-22 30 views
2

我已經知道如何用代碼趕上低於IOS如何動搖改變視圖

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 
{ 
    if (event.subtype == UIEventSubtypeMotionShake) 
    { 
     // Put in code here to handle shake 
     NSLog(@"Device Shaked");  


    } 

    if ([super respondsToSelector:@selector(motionEnded:withEvent:)]) 
     [super motionEnded:motion withEvent:event]; 
} 

搖晃手勢的NSLog表明,它沒有收到搖

,但如何把另一因爲我們知道下面的代碼只能在ViewController類中使用,而不是在View類中使用,所以這個Leavesview是由一個LeavesviewController處理的,並且我在另一個PDFViewController中使用這個viewController來顯示,所以我怎麼能它跳轉到另一個視圖或解僱?

UIViewController *myView = [[UIViewController alloc]init]; 
    [self.navigationController pushViewController:myView animated:YES]; 

回答

0

好吧,顯然我只是2個月前的首發。另外,答案顯然是Delegation;

1
See this complet Code...... 


     - (BOOL) canBecomeFirstResponder { 
      return YES; 
     } 

     - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { 

      if (event.subtype == UIEventSubtypeMotionShake) 
      { 
       // Work which you want 
      } 
     } 



    also dont forget these two methods... 

    -(void)viewDidAppear:(BOOL)animated{ 
     [super viewDidAppear:animated]; 
     [self becomeFirstResponder]; 

     } 


    -(void)viewDidDisappear:(BOOL)animated{ 
     [super viewDidDisappear:animated]; 
     [self resignFirstResponder]; 
    } 
+0

我不認爲'viewDidDisappear:'中的辭職應該被調用。這是無害的,但我們通常不添加代碼來辭退第一響應者。但是,否則,很好的答案。 –