IOS如何摇动改变View

发布于 2024-11-30 11:57:18 字数 774 浏览 1 评论 0原文

我已经知道如何使用下面的代码捕获摇动手势

    - (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 类中使用这个Leavesview不是View类,而是由LeavesviewController处理,并且我在另一个PDFViewController中使用这个viewController来显示,那么我怎样才能让它跳转到另一个视图或关闭回来???

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

I've already know how to catch the shake gesture with the code below

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

The NSLog shows that it did received the shake

but how to push another view,or back to the last view, as we know the code below can only use in ViewController class instead of View class, this Leavesview is handle by a LeavesviewController, and I use this viewController in another PDFViewController to display, so how could I make it jump to another view or dismiss back???

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隔纱相望 2024-12-07 11:57:18
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];
    }
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];
    }
下壹個目標 2024-12-07 11:57:18

好吧,显然我两个月前才刚刚起步。另外,显然答案是 委托;

Ok, Obviously I am just a starter 2 months ago. Also, obviously the answer is the Delegation;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文