如何完成“ 90%幻灯片”?在两个UIView之间 [英] How to accomplish a "90% slide" between two UIViews
问题描述
我有一个特定的场景正在尝试模仿,但是对于Cocoa Touch来说还很陌生,我不确定实现它的最佳方法。请原谅我缺乏战术知识;希望有一个明确的阐述会有所帮助。
我要模拟的内容:
我正在查看的应用程序(尤其是)是 Beat 。下面是其中一个UIView的示例-特别要注意底部的设置齿轮图标。
当触摸或滑动该齿轮时,将发生两个主要的UIView更改:
- 原来的UIView大约以90%的方式向上滑动到屏幕上(键点在于
- 将新的UIView向上滑动以填充新腾出的90%空间。
这是我要完成的基本功能。
实现思路1:单个UIViewController带有多个UIViews
首先,我考虑使用一个UIViewController来管理主视图和设置视图。在那种情况下,以适当的方式转换这些视图将是一件相当简单的事情。
这对我来说似乎有点混乱。根据我的两组功能的强大程度,这是使单个UIViewController重载的秘诀。您可能会告诉我这没关系,但事实并非如此。
实施思路2:自定义容器ViewController中有多个UIViewController
这是我当前要走的路线。它将两个离散的功能集分离为单独的UIViewControllers(包含在Container ViewController中),并通过以下两种方式在两者之间进行转换:
- (void)flipFromViewController:(UIViewController *)fromController
toViewController:(UIViewController *)toController
{
CGFloat width = self.view.frame.size.width;
CGFloat高度= self.view.frame.size.height;
fromController.view.frame = CGRectMake(0.0f,0.0f,宽度,高度);
toController.view.frame = CGRectMake(0.0f,height,width,height);
[self addChildViewController:toController];
[fromController willMoveToParentViewController:nil];
[self transitionFromViewController:fromController
toViewController:toController
持续时间:0.5f
选项:UIViewAnimationOptionTransitionNone
动画:^(void){
fromController.view.frame = CGRectMake(0.0f,-(高度-100.0f),宽度,高度);
toController.view.frame = CGRectMake(0.0f,100.0f,宽度,高度);
}
完成:^(布尔完成){
[fromController removeFromParentViewController];
[toController didMoveToParentViewController:self];
}];
}
问题在于过渡:它似乎并没有停止 90%的方式。看起来更像是要完全过渡出旧控制器,然后过渡到新控制器,即使我在两个UIView上的帧调整不应该是完整的动作。 / p>
我要指导的地方
我不是要完整的解决方案-您的专业知识将太昂贵。 :)就是说,作为新手,我很乐意您对正确方法的见解。
谢谢!
我确实认为您的第二个方法是正确的,并且您对使用transitionFromViewController:ToViewController的直觉也是正确的-如果您希望两个视图控制器都存在并处于活动状态,则我不会使用该方法。因此,我希望齿轮视图的控制器成为自定义容器控制器的子视图控制器,然后像您一样将第二个子窗口添加到屏幕底部。然后使用animateWithDuration动画两个视图:...最后,动画应具有所需的内容,并且容器控制器将有两个子代。
I have a particular scenario that I'm trying to emulate and, being fairly new to Cocoa Touch, I'm not sure of the best way to accomplish it. Pardon my lacking tactical knowledge; hopefully some clear exposition will help.
What I'd Like To Emulate:
The app I'm looking at (in particular) is Beat. Below is an example of one of their UIViews - in particular, notice the gear icon for Settings at the bottom.
When that gear is touched or swiped up, two primary UIView changes occur:
- The original UIView is slid up the screen about 90% of the way (the key point being that it does not slide all the way up).
- A new UIView is slid up to fill that newly vacated 90% space.
This is the basic functionality that I would like to accomplish.
Implementation Idea #1: Single UIViewController w/ Multiple UIViews
At first, I considered having a single UIViewController manage both the "main" and the "settings" views. In that case, it would be a fairly simple thing to transition these views in the appropriate manner.
That said, this seems a bit cluttered to me. Depending on how robust my two sets of functionality are, that's a recipe to overload a single UIViewController. You might tell me that that's okay, but off the bat, it seems too much.
Implementation Idea #2: Multiple UIViewControllers Within Custom Container ViewController
This is the route I'm currently going down. It separates the two discrete sets of functionality into separate UIViewControllers (contained within a Container ViewController) and transitions between the two via:
- (void)flipFromViewController:(UIViewController *)fromController
toViewController:(UIViewController *)toController
{
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height;
fromController.view.frame = CGRectMake(0.0f, 0.0f, width, height);
toController.view.frame = CGRectMake(0.0f, height, width, height);
[self addChildViewController:toController];
[fromController willMoveToParentViewController:nil];
[self transitionFromViewController:fromController
toViewController:toController
duration:0.5f
options:UIViewAnimationOptionTransitionNone
animations:^(void) {
fromController.view.frame = CGRectMake(0.0f, -(height - 100.0f), width, height);
toController.view.frame = CGRectMake(0.0f, 100.0f, width, height);
}
completion:^(BOOL finished) {
[fromController removeFromParentViewController];
[toController didMoveToParentViewController:self];
}];
}
The problem with this is the transition: it doesn't seem to stop "90% of the way". It looks more like it's intended to completely transition out an "old" controller and in a "new" controller, even though my frame adjustments on the two UIViews are not supposed to be "complete" moves.
Where I'd Like Guidance
I'm not asking for a complete solution - your expertise would be too expensive. :) That said, being fairly new to this, I would love your insight on what the right approach would be. Please let me know if I can provide further information.
Thanks!
I do think your 2nd method is on the right track, and your intuition about using transitionFromViewController:ToViewController is also right -- I wouldn't use that method if you want both view controllers to be present and active. So, I would have the controller with the gear view be a child view controller of a custom container controller, then add the second child off screen to the bottom like you have. Then animate both views up using animateWithDuration:... At the end of that, animation, you should have what you want, and you container controller will have two children.
这篇关于如何完成“ 90%幻灯片”?在两个UIView之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!