2013-07-12 4 views
0

StoryBoard은 iPhone4 해상도 용으로 구성되어 있으며 iPhone 5에서 실행 중일 때 UIView가 커질 수 있습니다 (두 높이 모두 & 너비가 됨).비례를 유지하면서 iPhone 5 화면에 맞도록 UI 크기 자동 조절

지금 문제는 이 더 높아지고 넓어지지 않는다는 것입니다.. 이를 달성하기 위해 자동 크기 조정 구성은 무엇이되어야합니까? enter image description here

+0

자동 레이아웃 사용 (떨림)? – Undo

+0

In에서는 iOS5에서도 작업해야하므로 자동 레이아웃은 옵션이 아닙니다. – Rizon

+0

흠 ... 하위 클래스를 사용하고 코드를 작성해야하는 것처럼 보입니다. 잠깐 ... – Undo

답변

1

enter image description here

당신은 아마 프레임 변경을 잡으려고 재정의 setFrame: 방법 UIView의 서브 클래스를 사용해야합니다.

- (void)setFrame:(CGRect)frame 
{ 
    frame.size.width = frame.size.height; // Make the *width* always equal to the *height*. Logic could go here, etc. 
    [super setFrame:frame] 
} 
+0

높이와 너비가 반드시 동일 할 필요는 없습니다. 그들은 비례하여 성장할 필요가 있습니다. – Rizon

+0

내 초기 상태 (200x200)는 단지 예일뿐입니다. 초기 높이 및 너비는 무엇이든 될 수 있습니다. – Rizon

+0

그런 다음 너비가 항상 높이의 1/3이되어야한다는 등의 논리를 추가 할 수 있습니다. – Undo

1

화면의 높이를 참조하고 패딩 값을 사용하여 뷰 프레임을 설정하십시오. 다음은 yourShapeView이라는 UIView의 프레임을 설정하는 코드입니다.

// Get the frame of the screen 
CGRect screenFrame = [[UIScreen mainScreen] bounds]; 

// Set padding from the top and bottom of the shape 
CGFloat verticalPadding = 40.0f; 
CGFloat horizontalPadding = 20.0f; 

// Get the height/width values 
CGFloat height = screenFrame.size.height - (verticalPadding * 2); 
CGFloat width = screenFrame.size.width - (horizontalPadding * 2); 

// Set the size of your shape based on the height and padding 
yourShapeView.frame = CGRectMake(horizontalPadding, verticalPadding, width, height); 
관련 문제