2013-11-15 1 views
0

사용자가 버튼을 누르면 비디오가 재생되고 모든 방향에 대해이 프로그램을 프로그래밍해야하는 프로젝트에서 작업하고 있습니다. 버튼의 배경이 같은 슈퍼 뷰의 크기에 따라 그 버튼의 위치를 ​​주어진 내가 이미지를 추가 한 :시작시 장치 방향 및 UIView와 관련된 문제

button1.frame = CGRectMake(0.15 * (self.view.frame.size.width),0.15 * (self.view.frame.size.height), 0.2 * (self.view.frame.size.width), 0.2 * (self.view.frame.size.height)); 

내가보기 좋은이며, 또한 내가 잘 작동 회전 할 때의 세로 응용 프로그램을 시작할 때 :

screenshot portrait

하지만 풍경에 내 응용 프로그램을 시작할 경우이 같은 전망을 보여줍니다

screenshot landscape

-(void) viewDidLoad 
{ 

... 
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | 
    UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | 
    UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 

[self.view setAutoresizesSubviews:YES]; 

button1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | 
    UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | 
    UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 
... 

} 

및 didRotateFromInterfaceOrientation() 및 willRotateToInterfaceOrientation()에서 : 0

I'v 조회수 및 파단 크기 조정 코드를 많이 사용

... 
    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | 
     UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | 
     UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 

    [self.view setAutoresizesSubviews:YES]; 

    button1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | 
     UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | 
     UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 
    ... 
을 shouldAutoRotate에 반환

I'v도 지정 YES(). 나는 여기서 무엇이 부족한가요? 어떤 도움을 주시면 감사하겠습니다.

+0

이 오래된 접근법을 없애고 Autolayout을 활용하십시오. 상황이 더 쉬울 것입니다. –

+0

고맙습니다.하지만 IOS 5.0 용으로 프로그래밍 중이며 .xib 파일이나 스토리 보드를 사용하지 않고 주문에 불복 할 수 없습니다. –

답변

1
you have to declaration below and all give them in viewDidLoad but frame give in 
this code 


-(void)viewWillAppear:(BOOL)animated 
{ 

    [self willAnimateRotationToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation duration:1.0]; 

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 

    if(orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft) 
    { 
    [self setFrameForLeftAndRightOrientation]; 
    } 
    else if(orientation == UIInterfaceOrientationPortrait) 
    { 
    [self setFrameForPortraitAndUpsideDownOrientation]; 
    } 
} 

    - (void)willAnimateRotationToInterfaceOrientation: 
    (UIInterfaceOrientation)toInterfaceOrientation 
     duration:(NSTimeInterval)duration 
    { 
      if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
      toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
      { 
      [self setFrameForLeftAndRightOrientation]; 
      } 
      else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) 
      { 
      [self setFrameForPortraitAndUpsideDownOrientation]; 
      } 
    } 

-(void)setFrameForLeftAndRightOrientation 
{ 
    if(IS_IPAD) 
    { 

    } 
    else if(IS_IPHONE) 
    { 

     if ([[UIScreen mainScreen] bounds].size.height == 568) 
     { 


     } 
     else 
     { 

     } 
    } 

} 

-(void)setFrameForPortraitAndUpsideDownOrientation 
{ 
    if(IS_IPAD) 
    { 

    } 
    else if(IS_IPHONE) 
    { 


    if ([[UIScreen mainScreen] bounds].size.height == 568) 
    { 


    } 
    else 
    { 

    } 
} 

}