在iOS5之前,将view controller的view加入到另一个vc的view中时,如下[parent_vc.view addSubview:sub_vc.view];
sub_vc的view appear,disappear等方法是不会被调用的。
在iOS5之后view controller内部,增加了一个属性:childViewControllers。
调用addChildViewController,就是把sub vc 加入到childViewControllers,这样,parent vc发生view appear,dispappear事件时,就轮循childViewControllers数组,依次调用其对应
方法就可以了。
removeFromParentViewController则是把一个vc从sub vc数组中去掉。
这样,这个vc就不会收到appear等事件了。
下面是UIViewController头文件相关的代码
/*
The methods in the UIContainerViewControllerProtectedMethods and the UIContainerViewControllerCallbacks
categories typically should only be called by subclasses which are implementing new container view
controllers. They may be overridden but must call super.
*/
@interface UIViewController (UIContainerViewControllerProtectedMethods)
// An array of children view controllers. This array does not include any presented view controllers.
@property(nonatomic,readonly) NSArray *childViewControllers NS_AVAILABLE_IOS(5_0);
/*
If the child controller has a different parent controller, it will first be removed from its current parent
by calling removeFromParentViewController. If this method is overridden then the super implementation must
be called.
*/
- (void)addChildViewController:(UIViewController *)childController NS_AVAILABLE_IOS(5_0);
/*
Removes the the receiver from its parent's children controllers array. If this method is overridden then
the super implementation must be called.
*/
- (void) removeFromParentViewController NS_AVAILABLE_IOS(5_0);
/*
This method can be used to transition between sibling child view controllers. The receiver of this method is
their common parent view controller. (Use [UIViewController addChildViewController:] to create the
parent/child relationship.) This method will add the toViewController's view to the superview of the
fromViewController's view and the fromViewController's view will be removed from its superview after the
transition completes. It is important to allow this method to add and remove the views. The arguments to
this method are the same as those defined by UIView's block animation API. This method will fail with an
NSInvalidArgumentException if the parent view controllers are not the same as the receiver, or if the
receiver explicitly forwards its appearance and rotation callbacks to its children. Finally, the receiver
should not be a subclass of an iOS container view controller. Note also that it is possible to use the
UIView APIs directly. If they are used it is important to ensure that the toViewController's view is added
to the visible view hierarchy while the fromViewController's view is removed.
*/
- (void)transitionFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(5_0);
// If a custom container controller manually forwards its appearance callbacks, then rather than calling
// viewWillAppear:, viewDidAppear: viewWillDisappear:, or viewDidDisappear: on the children these methods
// should be used instead. This will ensure that descendent child controllers appearance methods will be
// invoked. It also enables more complex custom transitions to be implemented since the appearance callbacks are
// now tied to the final matching invocation of endAppearanceTransition.
- (void)beginAppearanceTransition:(BOOL)isAppearing animated:(BOOL)animated __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
- (void)endAppearanceTransition __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
@end
分享到:
相关推荐
标题中提到的“Creating Container ViewControllers”,指的是创建容器视图控制器的过程,而描述中所讲的“如何建立container viewcontrollers结构”则是关于如何实际搭建这些容器视图控制器的层次结构。根据提供的...
综上所述,使用Swift开发实现ViewControllers之间的图片转换涉及了多个方面,从ViewController生命周期的理解,到自定义动画的实现,再到与用户的交互和性能优化,都是开发者需要掌握的关键技能。通过实践和学习,你...
6. **自定义容器控制器(Container View Controllers)**:如UIPageViewController,用于管理多个子控制器的视图转换。 7. **Block和Closure的使用**:在动画执行和回调中使用Block或Closure,使代码更加简洁和模块...
3. **Container View Controllers** - **UIContainerView**: 在Storyboard中,UIContainerView可以嵌套其他UIViewController,提供了一种在单一视图控制器中集成多个子视图控制器的方式,可以实现平滑的过渡效果。 ...
在视图控制器布局方面,可以使用Container View Controllers(如UINavigationController、UISplitViewController)或者自定义容器视图控制器来管理主视图和侧边栏视图。一种常见的方式是使用UIViewController的...
在iOS开发中,父控制器(Container View Controller)是一种可以包含一个或多个子控制器(Child View Controllers)的特殊控制器,用于组合多个视图控制器的功能和界面。这种设计允许开发者创建更复杂的UI结构,...
- `containerView`属性是容器视图,可以将子控制器的视图添加进去。 6. **Storyboard References**: - 在Storyboard之间创建引用,允许直接跳转到另一个Storyboard的视图控制器,减少了代码量。 - 使用`...
3. **自定义容器视图控制器(Container View Controllers)**:为了更好地管理抽屉视图和主视图,开发者可以创建自定义的容器视图控制器,继承自`UIViewController`。容器视图控制器可以控制其子控制器的生命周期和...
5. **Container View Controllers**: 这是实现复杂转场动画的另一种策略,通过嵌套的视图控制器,开发者可以方便地管理和协调不同视图之间的动画。 在实践中,开发者需要深入理解每个技术的原理,并结合实际需求...
5. **Container View Controllers**: 使用UINavigationController、UITabBarController等容器控制器,可以方便地管理侧边栏和主要内容之间的关系。有时也会自定义容器控制器以获得更精确的控制。 6. **第三方库**: ...
5. **Container View Controllers**:为了在主视图和侧边栏视图之间进行协调,开发者可能会使用Container View Controllers。这允许我们在一个父控制器中嵌入多个子控制器,从而实现更复杂的界面结构。 6. **...
4. **视图控制器容器(Container View Controllers)**: 为了同时显示主内容视图和侧边栏视图,开发者可能使用了`UIContainerView`或者自定义的容器视图控制器,如`UIStackView`,来管理两个子视图控制器的布局和...
4. **视图控制器容器(Container View Controllers)**:UINavigationController、UITabBarController等是内置的容器控制器,它们管理着多个子控制器的生命周期和转场。对于自定义转场,我们可以创建自定义的容器...
3. **视图控制器容器(Container View Controllers)**: - 子视图的显示与隐藏可能通过一个容器视图控制器来管理,比如`UIContainerView`或者自定义的容器视图控制器。容器视图控制器可以包含并管理多个子视图控制...
7. **Container View Controllers**: 在某些情况下,你可能需要在一个视图控制器内部嵌套其他视图控制器。通过使用容器视图控制器,如UISegmentedControl或UIPageViewController,你可以轻松地管理这些嵌套的转换...
let containerView = transitionContext.containerView if isPresenting { toView.transform = CGAffineTransform(scaleX: 0, y: 0) containerView.addSubview(toView) } else { containerView.insertSubview...
每个标签对应一个`UIViewController`,通过设置`tabBar.items`来定制标签的外观,然后在`viewControllers`属性中设置各个控制器。 为了实现高仿微信的底部导航栏切换动画,我们可能需要自定义过渡效果,例如平滑的...
此外,转场上下文提供了`containerView`属性,可以获取到参与转场的所有视图,开发者可以通过它来调整视图的位置和大小。转场协调器则允许我们在动画执行期间进行额外操作,如在`transitionCoordinator:...
这两个视图控制器可以通过容器视图(Container View)进行组合,或者使用` addChildViewController:` 和 `removeFromParentViewController:` 方法进行动态添加和移除。 三、布局与动画(Layout & Animation) 实现...