"didRotateFromInterfaceOrientation:" not called
hi i am traying to add subview a controller's view in a small view of the main view but 开发者_如何学JAVAthe didRotateFromInterfaceOrientation:. of the child controller isnt called so i canot make any changes for the change in the orientation
didRotateFromInterfaceOrientation will be called (in childViewController) only if you add childViewController to parentViewController like this:
[parentViewController addChildViewController:childViewController];
Note that, you still can switch that behavior on/off with a property:
self.automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers
It is set to YES by default, so in your case you don't need to touch it. Deprecated after iOS 6.0 Cheers
Do you have more than 1 UIViewController actively displaying its view on the screen at the same time? iOS really only expects 1 view belonging to a UIViewController on the screen at once. If there is more than 1 then only the UIViewController whose view is full screen will get its orientation change methods called.
I just wanted to post a follow up to this question. Post iOS 8, the rotate methods have been deprecated and instead you override viewWillTransitionToSize() in the child view controller.
NOTE: This method does appear to need you to add the child view controller as described above. I built my test using a storyboard and NavigationController and pushed on a new view controller when a button was pressed.
I set a breakpoint on this function and when I used the debugger to inspect: self->parentViewController->childViewControllers, childViewControllers was nil.
I had the same problem. Basically the
didRotateFromInterfaceOrientation:
is called for the root/parent view controller and If you are expecting this method getting called for a view controller, then the it must be child view controller of the current root view controller.
[self addChildViewController:YourUIViewController];
Per Apple document "When a rotation occurs for a visible view controller, the willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation: methods are called during the rotation. The viewWillLayoutSubviews method is also called after the view is resized and positioned by its parent. If a view controller is not visible when an orientation change occurs, then the rotation methods are never called. However, the viewWillLayoutSubviews method is called when the view becomes visible. Your implementation of this method can call the statusBarOrientation method to determine the device orientation."
But actually, even when the view is visible, for some reason (maybe because the view is not taking the full screen?), corresponding view controller's rotation related delegate methods won't be called. Overriding -viewWillLayoutSubviews might be a workaround for some cases.
It's a problem of life of the controller. I suspect that you instantiated the controller and added the subview then released the instance. Now if you are rotating the device you are not getting called the added subview rotation delegate methods.
Second reason is whenever you added the subview only parent view delegate will be called because the caller only have instance of the parentview controller. Caller may be navigation controller (navigation based application), tabbarcontroller (in case of tab based application). If you want to call subview method in the rotation you will need to call it explicitly like following:
if(subviewController != nil){
if([subviewController respondToSelector(rotateMethodOfSubView:)])
[subViewController performSelector(rotateMethodOfSubView:) withObject: self];
}
This should be helpful to solve the problem.
精彩评论