Reputation: 2343
In one of my applications I implemented a view that can play a movie. the oriantation of the view is Portrait. I overwrite the foloowing method so the view will rotate once the movie is playing.
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (isPlayingMovie) {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft );
} else {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
}
The problem is that the view will not automatically rotate. I figured that the view calles this method in the view controller only while it's loading but how can i force him to call it again ?
Thanks in advance.
Upvotes: 1
Views: 260
Reputation: 1624
Short answer: not possible.
Long answer: Just return that you do portrait only and rotate the view yourself.
Get rotation notifications (put it in viewDidAppear or something):
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(rotationChange:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
Then do the rotation in "rotationChange:" (example for a webview here):
- (void)rotationChange:(NSNotification *)notification {
UIDeviceOrientation o = [[UIDevice currentDevice] orientation];
CGFloat rotation;
[self.webView setTransform:CGAffineTransformIdentity];
switch (o) {
case UIDeviceOrientationPortrait:
rotation = 0;
case UIDeviceOrientationPortraitUpsideDown:
rotation = 180;
...
}
[[UIApplication sharedApplication] setStatusBarOrientation:o animated:YES];
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformRotate(transform, rotation * (M_PI / 180.0f));
[self.webView setTransform:transform];
}
EDIT: Don't forget to disable the notifications if you don't need them (like in "viewDidDisappear:")
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
Upvotes: 1
Reputation: 4396
Try using the code in this method
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration{
//required functionality
}
Cheers
Upvotes: 0