我正在制作app,就像设备改变它的方向模式一样,它改变了它的视图 首先,当视图是肖像时,它显示完美的SearchViewController,然后当我旋转到横向它推送到景观中的新视图MapView ...现在当我再次将视图更改为肖像时,地图旋转为肖像......但它应该是做搜索视图控制器...还有一件事,当我点击详细信息披露按钮时,它应该回到搜索视图控制器...我认为导航控制器不能在地图视图中工作..
这是我的searchViewController的代码部分
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
if(interfaceOrientation == UIInterfaceOrientationPortrait|| inte rfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
}
else {
MapView *mapView = [[MapView alloc] initWithNibName:@"MapView" bundle:nil];
mapView.title = @"Map";
[self.navigationController pushViewController:mapView animated:YES];
return YES;
}
return YES;
}
这是我的MapView代码
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
// return (interfaceOrientation == UIInterfaceOrientationLandscapeRight|| UIInterfaceOrientationLandscapeLeft);
if(interfaceOrientation == UIInterfaceOrientationPortrait|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
NSLog(@"hi Potrait");
[self.navigationController popViewControllerAnimated:NO];
return YES;
}
else {
}
return YES;
}
答案 0 :(得分:1)
shouldAutorotateToInterfaceOrientation:
是一个不正确的地方,可以实现任何类型的导航。您应该在didRotateFromInterfaceOrientation:
中执行此操作。检查当前interfaceOrientation
并在必要时按或弹出。
在searchViewController
,
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if ( UIInterfaceOrientationIsLandscape(self.interfaceOrientation) ) {
MapView *mapView = [[MapView alloc] initWithNibName:@"MapView" bundle:nil];
mapView.title = @"Map";
[self.navigationController pushViewController:mapView animated:YES];
}
}
在MapView
,
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if ( UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ) {
[self.navigationController popViewControllerAnimated:NO];
}
}
将您的shouldAutorotateToInterfaceOrientation:
改为
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}