单击信息按钮时如何在两个 UIViewController 之间进行翻转动画?
我有一个名为“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
翻转到视图控制器:
翻转出视图控制器:
To flip into a view controller:
To flip out of it:
我就是这样做的:
归功于 faysar 此处。
This is how I'm doing it:
Credit goes to faysar here.
你对 Cocoa Touch 中 MVC 结构的理解有一个根本性的缺陷,那就是,View Controllers 和 Views 是可比的和相似的。事实是,他们不是。
回到您的具体问题,是的,动画基于视图,而不是视图控制器。但每个视图都应该由视图控制器之一控制。哪个视图属于哪个控制器完全取决于您。在您的情况下,动画可能发生在具有 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.
简单的几行代码
simple lines of code