denvdancsk
denvdancsk

Reputation: 3053

Detect the duration of the Orientation Change for a subclass? iOS7

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?

Upvotes: 0

Views: 238

Answers (1)

Noah Witherspoon
Noah Witherspoon

Reputation: 57139

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.

Upvotes: 2

Related Questions