0

我有一个带有 pdf 的 UIviewController。我使用另一个屏幕中的方向来显示 pdf。方向运行良好 3 次,然后应用程序挂起并显示以下警告。

[切换到进程11779线程0x0]

[切换到进程13059线程0x0]

[切换到进程11779线程0x0]

它说什么?请在下面找到代码。

- (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];
}

任何帮助表示赞赏。谢谢你

4

1 回答 1

0

而不是做这个复杂的任务,你应该使用 ios 提供的默认方法来处理方向的东西:

只需将以下代码添加到您的.m文件中:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return YES;
}
于 2011-05-18T05:16:12.483 回答