2012-04-12 4 views
1

appdelagteクラスのnavigationcontrollerに画像を追加しました。 とyesに設定するiPadアプリで向きを管理する方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    loginViewController = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil]; 

    [self.window addSubview:_navController.view]; 

    _navController.navigationBarHidden = NO; 
    navimage = [[UIImageView alloc] init]; 
    navimage.frame = CGRectMake(300, 18, 177, 47); 

    navimage.image = [UIImage imageNamed: @"logo.png"]; 

    [_navController.view addSubview:navimage]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ 
return YES; 
} 

しかし、ナビゲーション画像の位置は変更されていません。フレームは両方のモードで同じままです。

ナビゲーションコントローラの画像の場合、どのように解決されるか考えてください。

答えて

1

あなたのコントローラであなたのコントローラのviewDidLoadメソッドとshouldAutorotateToInterfaceOrientationでこれを追加する必要があります。

-(void)viewDidLoad{ 
navimage = [[UIImageView alloc] init]; 
navimage.frame = CGRectMake(300, 18, 177, 47); 

navimage.image = [UIImage imageNamed: @"logo.png"]; 

[_navController.view addSubview:navimage]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ 
return UIInterfaceOrientationIsPortrait(toInterfaceOrientation); 
} 
1
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ 
    return YES; 
} 

上記のコードはUIViewControllerクラス(あなたのケースではLoginViewController)ではなく、AppDelegateで記述する必要があります。あなたが唯一の肖像画の向きを必要とする場合

そして、これを使用する:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ 
    return UIInterfaceOrientationIsPortrait(toInterfaceOrientation); 
} 
関連する問題