IOS如何动摇改变观点

时间:2011-08-22 05:16:04

标签: ios uiviewcontroller shake

我已经知道如何使用下面的代码抓住摇晃手势

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

2 个答案:

答案 0 :(得分: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];
    }

答案 1 :(得分:0)

好的,显然我2个月前才刚刚入手。此外,答案显然是Delegation;