I have a UIviewController with a pdf in it. I use the orientation in another screen to display the pdf. The orientation works well three times and then the app hangs with the below warning.
[Switching to process 11779 thread 0x0]
[Switching to process 13059 thread 0x0]
[Switching to process 11779 thread 0x0]
What does it says? Please find the code below.
- (void)viewDidLoad
{
self.view.backgroundColor = [UIColor clearColor];
pdfURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Sample" ofType:@"pdf"]];
[webView loadRequest:[NSURLRequest requestWithURL:pdfURL]];
thisDevice = [UIDevice currentDevice];
[thisDevice beginGeneratingDeviceOrientationNotifications];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:UIDeviceOrientationDidChangeNotification object:nil];
[self setTitle:@"1 Of 1"];
[super viewDidLoad];
}
-(void) detectOrientation
{
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
//load view 2
IdcardVC *ids = [[IdcardVC alloc] initWithNibName:@"IdcardVC" bundle:nil];
[self.navigationController presentModalViewController:ids animated:YES];
[ids release];
}
else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) 开发者_如何转开发{
[self dismissModalViewControllerAnimated:NO];
}
Any help is appreciated. Thank You
Instead of doing this complicated task you should use the default method provided ios to deal with orientation stuff:
Just Add thee following code to your .m file:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return YES;
}
精彩评论