2

我已经知道如何使用下面的代码来捕捉摇晃手势

    - (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];
4

2 回答 2

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];
    }
于 2013-05-02T05:01:03.603 回答
0

好的,显然我只是 2 个月前的初学者。此外,显然答案是代表团

于 2011-10-22T09:54:13.323 回答