2013-04-01 2 views
0

iPad 용 자동 회전 작업을하고 있지만 이상한 문제가 있습니다.자동 회전이 올바르게 일어나지 않습니다.

내가보기에는 ipad를 세로보기로 사용하고 ipad를 가로로 회전하면 문제가 발생합니다. 그것은 초상화가 아닌 풍경의 크기를 보여줍니다. 같은 방식으로 내가 가로보기로 ipad를 사용하고 세로보기로 ipad를 회전하면. 풍경이 아닌 초상화가 표시됩니다. 아래의 코드를 사용하여 객체의 크기를 변경하고 있습니다.

- (void)viewDidLoad { 

UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation; 
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight 
     || interfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
    { 
     table.frame = CGRectMake(83, 600, 550, 275); 
      im.frame = CGRectMake(0, 62, 775, 70); 
      im1.frame = CGRectMake(0, 135, 775, 40); 
     im2.frame = CGRectMake(60, 325, 650, 550); 
     l17.frame = CGRectMake(0, 62, 775, 70); 
     l16.frame = CGRectMake(85, 145, 780, 40); 
      l15.frame = CGRectMake(83, 200, 600, 40); 
     img.frame = CGRectMake(550, 300, 150, 110); 
     l18.frame = CGRectMake(28, 550, 650, 40); 
      b7.frame = CGRectMake(83, 880, 600, 40); 
     //[self.view addSubview:table]; 

    } 

    [super viewDidLoad]; 
} 

나에게 무슨 일이 잘못 됐는지 제안 해 주시겠습니까?

답변

0
-(void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration { 

    if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) 
     table.frame = CGRectMake(83, 600, 550, 275); 
     im.frame = CGRectMake(0, 62, 775, 70); 
     im1.frame = CGRectMake(0, 135, 775, 40); 
     im2.frame = CGRectMake(60, 325, 650, 550); 
     l17.frame = CGRectMake(0, 62, 775, 70); 
     l16.frame = CGRectMake(85, 145, 780, 40); 
     l15.frame = CGRectMake(83, 200, 600, 40); 
     img.frame = CGRectMake(550, 300, 150, 110); 
     l18.frame = CGRectMake(28, 550, 650, 40); 
     b7.frame = CGRectMake(83, 880, 600, 40); 
    else 
     tableView.frame = CGRectMake(0,73,320,390); 
     -- 
     -- 

} 

시도해 보셨습니까?

+0

이 방법을 통과하지 못했습니다 –

+0

오른쪽 회전 만하는 사이징 문제가 있습니까? – wesley

0

오리 엔테이션 확인을위한 코드 작동 여부

코드 :

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; 
    ...... 
} 

확인 방법 : 방향 변경 방법 PCH 파일에서

에 대한

-(void)orientationChanged { 

    NSLog(@"Orientation Changed..!!"); 

    UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation; 

    //Lanscape View 
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight 
    || interfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
    { 
     table.frame = CGRectMake(83, 600, 550, 275); 
     ..... 
    } 

    //Portrait View 
    else 
    { 
     table.frame = CGRectMake(x, y, w, h); 
     ..... 
    } 
} 

코드,

#define IOS_OLDER_THAN_6  ([ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0) 
#define IOS_NEWER_OR_EQUAL_TO_6 ([ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0) 
하는 .m 파일에서

,

//For Less than IOS 6 

#ifdef IOS_OLDER_THAN_6 
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return toInterfaceOrientation; 
} 
#endif 

// For Newer than IOS 6. 
#ifdef IOS_NEWER_OR_EQUAL_TO_6 
-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 
- (NSUInteger)supportedInterfaceOrientations 
{ 
    return (UIInterfaceOrientationMaskAll); 
} 
#endif 

희망, 그것은 당신에게 도움이 될 것입니다.

감사합니다.

관련 문제