Domanda

I am creating a UIScrollView subclass that needs to run an animation when the device orientation changes. In order to do that I need to know the exact duration of the orientation change. In a view controller I would have just used this:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"%f", duration);
}

Since this is in a subclass I need to use the following code instead:

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(orientationChanged:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil];

And then call the selector:

-(void)orientationChanged:(id)selector
{
    NSLog(@"Orientation has changed");
}

The only problem is it doesn't tell me the duration of the device orientation. Does anyone know how to get it?

È stato utile?

Soluzione

The property you’re looking for is UIApplication’s statusBarOrientationAnimationDuration. That’s for a 90° rotation—double it if you’re handling a 180° one.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top