2013-04-19 3 views
1

두 개의 텍스트 레이블과 두 개의 버튼이있는 UIView 사용자 정의를 만들었습니다. 생성 될 때 완전히 기능하지만 화면이 회전 할 때 (예 : 세로에서 가로로) 이동하려고합니다.방향이 바뀌면 UIView 프레임이 올바르게 업데이트되지 않습니다.

UI 요소가 제대로 이동 된 것처럼 보이지만 실제 UIView의 프레임은 원래 사각형이었을 때 사각형으로 바뀌고 사각형으로 설정되지만 다른 x, y 위치.

내가 이것을 보았는지는 내 UIView의 배경색을 검정색으로 설정하고 내 배경 이미지가 그려지는 곳에서 볼 수 있지만 뷰가 그려지는 곳을 관찰하는 것이지만 UIView의 배경이 다른 모양이되어 그려진다. 잘못된 곳에서. 여기

내 코드입니다 :

- (void) moveControls 
{ 
    CGRect frame; 

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 
    switch (orientation) 
    { 
     case UIDeviceOrientationPortrait: 
     case UIDeviceOrientationPortraitUpsideDown: 
      frame = CGRectMake(0, 120, 320, 320); 
      break; 
     case UIDeviceOrientationLandscapeLeft: 
     case UIDeviceOrientationLandscapeRight: 
      frame = CGRectMake(120, 0, 320, 320); 
      break; 
     case UIDeviceOrientationFaceDown: 
     case UIDeviceOrientationFaceUp: 
     case UIDeviceOrientationUnknown: 
      return; 
    } 

    [self setFrame:frame]; 

    backgroundImage.frame = CGRectMake(0,0, frame.size.width, frame.size.height); 
    titleLabel.frame = CGRectMake(0,50,frame.size.width,frame.size.height/2); 
    titleLabel.numberOfLines = 0; 
    titleLabel.lineBreakMode = NSLineBreakByWordWrapping; 
    textLabel.frame = CGRectMake(0,frame.size.height/3,frame.size.width,frame.size.height/3); 
    doneButton.frame = CGRectMake(frame.size.width - 154, frame.size.height - 90, 100, 34); 
    tellButton.frame =CGRectMake(54, frame.size.height - 90, 100, 34); 
} 

답변

4

정말 모든 질문에 대답하지만 문제가 해결되지 않습니다 : ios: UIView's width and height after changing orientations is inaccurate?

view.center = view.superview.center; 
view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 
0

사용 :

- (void) moveControls 
{ 
    CGRect frame; 

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 
    if (UIDeviceOrientationIsLandscape(orientation)) 
     frame = CGRectMake(120, 0, 320, 320); 
    else 
     frame = CGRectMake(0, 120, 320, 320); 



    [self setFrame:frame]; 

    backgroundImage.frame = CGRectMake(0,0, frame.size.width, frame.size.height); 
    titleLabel.frame = CGRectMake(0,50,frame.size.width,frame.size.height/2); 
    titleLabel.numberOfLines = 0; 
    titleLabel.lineBreakMode = NSLineBreakByWordWrapping; 
    textLabel.frame = CGRectMake(0,frame.size.height/3,frame.size.width,frame.size.height/3); 
    doneButton.frame = CGRectMake(frame.size.width - 154, frame.size.height - 90, 100, 34); 
    tellButton.frame =CGRectMake(54, frame.size.height - 90, 100, 34); 
} 
+0

감사하지만, 여전히 똑같은 것. :( –