Can I rotate UIView without black bars?

I have a UIView that takes up the entirety of a window on an iphone. When it turns to the landscape, the edges get little black stripes until it snaps into place as I expected.

I want to make this uiview larger than the screen, so that rotating it does not show those black bars, but shows parts of the view that would normally look like onscreen. I've tried increasing the view's frame and borders, but it doesn't seem like a trick.

Has anyone done this successfully?

+3


source to share


4 answers


You need to do two things for this to happen.

First, the root window controller will always resize its window to the size of the window. Thus, your large view must be subordinate to the root view controller (so it doesn't change), and the root view controller view must be clipsToBounds

set to NO. In fact, all ancestors of a large species must have clipsToBounds

for NO.



Second, when the window is rotated, it gives the black subtitles explicitly hiding any views that would otherwise appear outside the window's bounds. It puts these black sub-selections in front of the root view controller's view. You need to bring the root view controller's view to the front, for example:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    UIWindow *window = self.view.window;
    [window bringSubviewToFront:window.rootViewController.view];
}

      

+2


source


I found an alternative way that works when you have two UIWindows overlaps. (This might be the case if you want non-rotated content in the background, with a rotating interface floating on top.) The idea is to directly look for the sub-visible black bars in the front-most UIWindow when the call to AnimateRotationToInterfaceOrientation is invoked, and explicitly hide them The following code searches at two levels:



-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
    UIWindow* window = self.view.window;
    for (UIView* view in [window subviews]) {
        if (!CGRectIntersectsRect(window.bounds, view.frame)) {
            view.hidden = YES;
        }

        for (UIView* view_ in [view subviews]) {
            CGRect frame = [view_ convertRect:view_.frame toView:window];
            if (!CGRectIntersectsRect(window.bounds, frame)) {
                view_.hidden = YES;
            }
        }
    }
}

      

+2


source


I am currently working on an application that requires the screen to rotate at a slower speed. To stop the black rotation rectangle clipping the view (at standard rotation speed) before starting my rotation, I just checked the box next to General -> Deployment Info -> Requires full screen .

enter image description here

I also have the status bar hidden on the view controller, although the hide status bar field is not checked.

0


source


UINavigationController and UITabBarController have system subtasks (UINavigationController: UINavigationTransitionView; UITabBarController: UITransitionView and UIViewControllerWrapperView) with layer.masksToBounds set to YES. To eliminate black edges during rotation, you must set these and all other hierarchical view.masksToBounds to NO.

However, I'm not sure what the effect of changing the layers of the aforementioned system views is, so I recommend resetting their layer.masksToBounds back to YES after you're done animating.

0


source







All Articles