Question

So I have incorporated Mr. Grant Davis' FGallery into my app for a photo gallery. It works great other than it is overriding all my rotation methods in my other views and I cannot for the life of me figure out how to stop it. Here's a snippet from FGallery's FGalleryViewController that handles the gallery:

@implementation UINavigationController (FGallery)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

   if([self.visibleViewController isKindOfClass:[FGalleryViewController class]]) {
        return YES;
    }

    // we need to support at least one type of auto-rotation we'll get warnings.
    // so, we'll just support the basic portrait.
    return ( interfaceOrientation == UIInterfaceOrientationPortrait ) ? YES : NO;
}

I have tried changing the line:

    return ( interfaceOrientation == UIInterfaceOrientationPortrait ) ? YES : NO;

but that forces all views to that specific orientation. Some of my views allow for rotation and some do not. So I guess my question is, how can I alter this line to allow rotation in some views and not in others? I'm drawing a blank this morning!!

Any help or ideas here would be appreciated!!

Was it helpful?

Solution

So I'm gonna go ahead and answer my own question.

The answer is to remove the code that overrides the rotation:

@implementation UINavigationController (FGallery)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if([self.visibleViewController isKindOfClass:[FGalleryViewController class]]) 
    {
        return YES;
    }

    // we need to support at least one type of auto-rotation we'll get warnings.
    // so, we'll just support the basic portrait.
    return ( interfaceOrientation == UIInterfaceOrientationPortrait ) ? YES : NO;
}


- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    // see if the current controller in the stack is a gallery
    if([self.visibleViewController isKindOfClass:[FGalleryViewController class]])
    {
        FGalleryViewController *galleryController = (FGalleryViewController*)self.visibleViewController;
        [galleryController resetImageViewZoomLevels];
    }
}

@end

And call:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

within @implementation FGalleryViewController

Hopefully this helps someone else out that needs it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top