내 UINavigationBar의 사용자 정의 모양을 만들려고합니다. 사용자가 앱을 가로 방향으로 배치하면 탐색 표시 줄이 이미지로 덮여 야합니다. 다시 세로로 회전하면보기 (이미지)가 제거됩니다. 제거하는 것을 제외하고는 아래의 코드로 모든 것이 잘 작동합니다. 같은 if 문에 코드를 삽입하면 View를 제거 할 수 있지만 else if 문에 넣으면 아무 일도 발생하지 않습니다. 내가 놓친 게 있니?/감사합니다UINavigationBar에 subView 추가 및 제거
- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {
UIView *v = [[UIView alloc]init];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
v.frame = CGRectMake(0,0,480,44);
v.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"navbar25g.png"]];
[self.view addSubview:v];
//[v removeFromSuperview]; <----- works if I put it here
NSLog(@"LANDSCAPE");//load the landscape view
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
[v removeFromSuperview]; <----- Not working
NSLog(@"PORTRAIT"); //load the portrait view
}
}