开发者

Autorotation on a gallery - willAnimateRotation... isn't invoked

开发者 https://www.devze.com 2023-01-22 07:37 出处:网络
I\'m using this. I\'ve put this in where the images are added: self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

I'm using this.

I've put this in where the images are added:

self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

I've put these overrides in SlideShowViewController:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return YES;
}

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)InterfaceOrientation duration:(NSTimeInterval)duration {


}

The first is called, but not the second.

I'm not using a nib; it uses a custom init which returns a self.view with the 3 images on it.

Am I missing something? What would be the best way to modify this script to get the landscape photos stretch to full width when the iPhone is rotated by the user?

Edit: Just tried adding willAnimate... to the Root View Controller of my NavigationController, but it's not invoked. Perhaps the NavigationController is the problem? In that case, where do I put the willAnimate...? Alternatively, how do I receive and pass on messages sent to it towards the visible viewController?

Edit 2: Cause of the error in topic was that the TabBarController was missing a connection in IB (which I was sure was there). So now my problem is the same as for a few other similar questions - willAnimate... is called in root VC but not in the pushed VCs. The code I've used fades in the gall开发者_开发技巧ery VC rather than slide it in, ie. it's not pushed but currently added as a subview to the window - to fill the entire display.

Suggestions for how to message that subview's controller to set the frames would be appreciated, or alternate solutions!


This is not an answer to why your "willAnimateRotation.."-method doesn't trigger but instead an alternative to how the image gallery can adapt to rotations itself.

In initWithImages add:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(didRotate:)
                                             name:UIDeviceOrientationDidChangeNotification object:nil];

Add this method to receive the notification. In didRotate you can handle the resizing an repositioning of the images.

- (void) didRotate:(NSNotification *)notification
{   
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

    if (orientation == UIDeviceOrientationLandscapeLeft)
    {
        NSLog(@"Landscape Left!");
    }
}

Don't forget to unregister the notification in dealloc:

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];

May I also suggest that you use a UIScrollView instead of handling scrolling and gestures yourself?


Is SlideShowViewController pushed directly onto the Navigation Controller stack, or is it part of some other view? The UIView delegate methods get kind of messed up when working with subviews on views on the Navigation Controller stack.

If SlideShowViewController is just a subview of some other view that's been pushed onto the Navigation Controller stack, I would try to listen for this method in the view controller that is actually on the Navigation Controller stack, and then calling the appropriate method in SlideShowViewController from there.


I had a similar problem in getting viewWillAppear and similar method called within a navigation controller.
I solved by calling them manually when the root method is called.
I don't know if it's the same issue with rotation, but you may try putting in your root view controller

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)InterfaceOrientation duration:(NSTimeInterval)duration {
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    [self.navigatioController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}


This question was a bit tricky to answer I guess, since it was about my specific non-rudimentary app setup. Sorry for letting the bounty time run out, it was basically too late the same day I asked ;)

I thought I'd post this 'not buried in comments' for anyone who gets the same symptoms.

The first was that I noticed an IBOutlet that I'm sure I connected at one point was no longer connected (Tab Bar Controller -> tabBarController object). Since I was racking my brains and moved stuff around to make this work, this probably was due to me trying something and then restoring a backup.

Second part of the solution was to addSubView the gallery view to the tabBarController's view instead of the navigated-to view. Then the root view controller's shouldAuto... and willAuto methods were invoked.

(To hide the Tab Bar and Navigation Bar while rotating I had to set their .alpha to 0 while the gallery is displayed, otherwise the navigated-to view was partly hidden under the navigation Bar when returning to it. I found no way of hiding the status bar while showing the gallery.)

After this there was a request to have the gallery in a detail-view navigated to from another tab, and I got the tricky error that only while the OTHER (working) detail-view was shown under the other tab would autorotate work with the new gallery. Will get back to the solution to this, quittin time.

0

精彩评论

暂无评论...
验证码 换一张
取 消