单击信息按钮时如何在两个 UIViewController 之间进行翻转动画?

发布于 2024-10-10 15:34:22 字数 1569 浏览 6 评论 0原文

我有一个名为“LoginViewController”的登录页面。我在此页面中有一个信息按钮。如果我单击它,我想显示有关我的应用程序的一些信息。我还想使用翻转动画来呈现该信息页面。

创建信息按钮的代码是,

infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
infoButton.frame = CGRectMake(285, 425, 30, 30);
infoButton.backgroundColor = [UIColor clearColor];

[infoButton addTarget:self 
            action:@selector(displayInfoView) 
            forControlEvents:UIControlEventTouchUpInside];

如果我单击信息按钮,将调用 displayInfoView 方法。在那里我可以显示一个 UIView 来显示一些信息。我说得对吗?

对于翻转动画,我使用了这段代码...

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:.8];

[UIView setAnimationTransition:([loginPageView superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) 
        forView:mainView
        cache:YES]; 

if ([infoView superview]) {
    [infoView removeFromSuperview];
    [mainView addSubview:loginPageView];
}
else {
    [loginPageView removeFromSuperview];
    [mainView addSubview:infoView];
}

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];

这里 loginPageView 是包含信息按钮的登录视图。 infoView 是包含应用程序信息的视图。 mainView 是保存当前视图的公共视图。

现在我的问题是,我可以在单击信息按钮时显示另一个视图控制器类,而不是显示 UIView 吗?请记住,翻转操作可以在 UIView 上正常工作。但是当我尝试使用 UIViewController 时,这会带来麻烦。

有人可以建议我如何在单击具有翻转效果的信息按钮时显示 UIViewController (在我的应用程序中,我需要显示 AboutViewController)?

I have a login page named "LoginViewController". I have an info button in this page. If I click on it, I want to show some information about my application. Also I want to present that information page using flip animation.

The code for creating info button is,

infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
infoButton.frame = CGRectMake(285, 425, 30, 30);
infoButton.backgroundColor = [UIColor clearColor];

[infoButton addTarget:self 
            action:@selector(displayInfoView) 
            forControlEvents:UIControlEventTouchUpInside];

If I click on the info button, the displayInfoView method will be called. There I can show a UIView to display some information. Am I right?

For flip animation, I used this code...

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:.8];

[UIView setAnimationTransition:([loginPageView superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) 
        forView:mainView
        cache:YES]; 

if ([infoView superview]) {
    [infoView removeFromSuperview];
    [mainView addSubview:loginPageView];
}
else {
    [loginPageView removeFromSuperview];
    [mainView addSubview:infoView];
}

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];

Here loginPageView is the login view that contains the info button. infoView is the view that contains the information about application. mainView is the common view that holds the present view.

Now my problem is, instead of showing a UIView, can I show an another view controller class while clicking the info button? Remember the flip action works fine with UIView. But when I try with a UIViewController, this makes trouble.

Can someone suggest me how to show an UIViewController ( in my app, I need to show AboutViewController) while clicking the info button with the flip effect?

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

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

发布评论

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

评论(5

绾颜 2024-10-17 15:34:22

翻转到视图控制器:

viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:viewController animated:YES completion:nil];

翻转出视图控制器:

[self dismissViewControllerAnimated:YES completion:nil];

To flip into a view controller:

viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:viewController animated:YES completion:nil];

To flip out of it:

[self dismissViewControllerAnimated:YES completion:nil];
满地尘埃落定 2024-10-17 15:34:22

我就是这样做的:

 AboutShowViewController *aboutShowViewController = [[AboutShowViewController alloc] initWithNibName:@"AboutShowViewController" bundle:[NSBundle mainBundle]];

    [UIView beginAnimations:@"View Flip" context:nil];
    [UIView setAnimationDuration:0.80];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight 
                           forView:self.navigationController.view cache:NO];

    [self.navigationController pushViewController:aboutShowViewController animated:YES];
    [UIView commitAnimations];

    [aboutShowViewController release];

归功于 faysar 此处

This is how I'm doing it:

 AboutShowViewController *aboutShowViewController = [[AboutShowViewController alloc] initWithNibName:@"AboutShowViewController" bundle:[NSBundle mainBundle]];

    [UIView beginAnimations:@"View Flip" context:nil];
    [UIView setAnimationDuration:0.80];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight 
                           forView:self.navigationController.view cache:NO];

    [self.navigationController pushViewController:aboutShowViewController animated:YES];
    [UIView commitAnimations];

    [aboutShowViewController release];

Credit goes to faysar here.

静若繁花 2024-10-17 15:34:22

你对 Cocoa Touch 中 MVC 结构的理解有一个根本性的缺陷,那就是,View ControllersViews 是可比的和相似的。事实是,他们不是。

回到您的具体问题,是的,动画基于视图,而不是视图控制器。但每个视图都应该由视图控制器之一控制。哪个视图属于哪个控制器完全取决于您。在您的情况下,动画可能发生在具有 2 个不同控制器的 2 个视图之间,或者也可能发生在同一控制器的 2 个视图之间。

至于代码示例,我建议您看一下 Xcode 的默认模板之一,实用程序应用程序,它以简洁且标准化的方式实现了这种点击和翻转动画。

There is a fundamental flaw in your understanding of the MVC structure in Cocoa Touch, which is, View Controllers and Views are comparable and similar. The truth is, they are Not.

Back to your specific question, yes, animations are based on views, not on view controllers. But each view should be controlled by one of your view controllers. And this which-view-belongs-to-which-controller thing is totally up to you. In your case, animation could happen between 2 views with 2 different controllers, or, they could also happen between 2 views of the same controller.

As for code samples, I suggest you take a look at one of Xcode's default templates, the Utility Application, which has implemented this click-and-flip animation in a succinct and standardized way.

玩套路吗 2024-10-17 15:34:22
  override func viewWillDisappear(_ animated: Bool) {
      super.viewWillDisappear(true)
      // for back button
      changeTransition()
  }
        //btnMap.addTarget(self, action: #selector(searchHotelsResultVC.goToMap), for: .touchUpInside)
       //btnMap.addTarget(self, action: #selector(MapViewController.backToList), for: .touchUpInside)
func goToMap()  {
      // for pushing
     changeTransition()
navigationController?.pushViewController(settingsVC, animated: false)
}
func backToList()  {
        // for dismiss 
        changeTransition()
        navigationController?.popViewController(animated: false)
        dismiss(animated: true, completion: nil)

    }
    func changeTransition()  {
        let transition = CATransition()
        transition.duration = 0.5
        transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
        //transition.type = kCATransitionPush
        transition.type = "flip"
        transition.subtype = kCATransitionFromLeft
        navigationController?.view.layer.add(transition, forKey: kCATransition)

    }
  override func viewWillDisappear(_ animated: Bool) {
      super.viewWillDisappear(true)
      // for back button
      changeTransition()
  }
        //btnMap.addTarget(self, action: #selector(searchHotelsResultVC.goToMap), for: .touchUpInside)
       //btnMap.addTarget(self, action: #selector(MapViewController.backToList), for: .touchUpInside)
func goToMap()  {
      // for pushing
     changeTransition()
navigationController?.pushViewController(settingsVC, animated: false)
}
func backToList()  {
        // for dismiss 
        changeTransition()
        navigationController?.popViewController(animated: false)
        dismiss(animated: true, completion: nil)

    }
    func changeTransition()  {
        let transition = CATransition()
        transition.duration = 0.5
        transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
        //transition.type = kCATransitionPush
        transition.type = "flip"
        transition.subtype = kCATransitionFromLeft
        navigationController?.view.layer.add(transition, forKey: kCATransition)

    }
微暖i 2024-10-17 15:34:22

简单的几行代码

YourViewController *city = [self.storyboard instantiateViewControllerWithIdentifier:@"YourViewController"];
[UIView beginAnimations:nil context:nil];
[UIView  setAnimationDuration:.5];
[self.navigationController pushViewController:city animated:YES];
[UIView  setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

simple lines of code

YourViewController *city = [self.storyboard instantiateViewControllerWithIdentifier:@"YourViewController"];
[UIView beginAnimations:nil context:nil];
[UIView  setAnimationDuration:.5];
[self.navigationController pushViewController:city animated:YES];
[UIView  setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文