Scrapbook/개발 및 프로그래밍

이전 프로젝트 아이폰5 해상도 대응

가을이짱짱 2013. 1. 8. 18:11
반응형

이통사 서비스 유지보수를 하며,

아이폰5 해상도 대응으로 고민하던차 좋은글이 있어 옮겨봅니다.

 

1. Project - Build Settings - Valid Architectures에 armv7s를 추가해줍니다.
2. Default-568h@2x.png 파일을 추가해줍니다. (이 파일이 없으면 아이폰5 해상도로 안나옵니다.)

기본적으로는 위의 작업만 하시면 아이폰5용 해상도로 출력됩니다.
아이폰5가 없으시면 시뮬레이터로 보시면 됩니다.

해상도 작업은 이미지가 아닌경우 SDK4.5부터 지원하는 Constraints를 통해서 늘려줄 수 있지만
이미지인 경우에는 해상도에 맞는 이미지파일을 따로 마련하시거나 위치를 조정해주셔야합니다.

아이폰이 3.5인치 일때는 좌표가 항상 같았기 때문에 좌표를 지정해놓는 경우가 많았습니다.
[webView setFrame:CGRectMake(0,50,320,460)]; 이런식으로요.
이런식의 코딩을 많이 해놓으셨다면 일일히 다 바꾸어줘야합니다.

[UIScreen mainScreen]을 많이 활용하시면 될것 같습니다.

혹시나 아이폰5해상도에서도 좌표를 지정해줘야한다면


if ([[UIScreen mainScreen] bounds].size.height == 568.0000) { //2013-01-24 최근 개발하다보니 값이 float 로 리턴되더라고요^^

// 아이폰 4인치 해상도 (아이폰5)

} else {

// 아이폰 3.5인치 해상도

}


이렇게 구분해주시면 됩니다.

 

참고사이트: http://cafe.naver.com/mcbugi/236038

 

http://blog.mugunthkumar.com/coding/supporting-the-iphone-5/

 

iPhone 5 is out and it poses a new challenge to developers, a bigger screen. iOS developers have never been required to support multiple device resolutions in the past. But fret not, Apple has made things easy for us. Follow the four steps below and you are all set.

Step 1:

iPhone 5 requires a new instruction set, the armv7s. Only the latest Xcode, version 4.5 as on writing supports generating armv7s instruction set. Do note that, Xcode 4.5 no longer supports armv6 and deprecates iPhone 3G and older devices. So, build your app using Xcode 4.5

Step 2:

The next step is to add a launch image (Default-568h@2x.png). When you build your project with Xcode 4.5, you will see a warning, “Missing Retina 4 launch image”. Click “Add” to add a default image to your project.

Xcode 4.5 prompting for addition of a launch image for iPhone 5

Xcode 4.5 prompting for addition of a launch image for iPhone 5

The app now launches in full screen on iPhone 5 without letter boxing on iPhone 5.

Step 3:

However, most of your nib files will still not scale properly. The next step is to check your auto resizing mask of every nib file and ensure that the view inside the nib file automatically sizes based on super view’s height.

Changing the auto resize mask

Changing the auto resize mask

The properties that you would use are UIViewAutoresizingFlexibleTopMargin, UIViewAutoresizingFlexibleBottomMargin, UIViewAutoresizingFlexibleHeight.
You use the UIViewAutoresizingFlexibleHeight for the top most view so that it autosizes with the main window. You use the UIViewAutoresizingFlexibleTopMargin and/or UIViewAutoresizingFlexibleBottomMargin for subviews.

The UIViewAutoresizingFlexibleTopMargin is used if you want the subview to be “pinned” to the bottom (top margin is flexible) and UIViewAutoresizingFlexibleBottomMargin is used if you want the subview to be “pinned” to the top (bottom margin is flexible).

When you use Cocoa Auto Layout, this step becomes optional. However, Auto Layout is not supported on iOS 5.

Step 4 (optional):

Lastly, any CALayer that you added to the view will have to be manually resized. The code below shows how to do this. I usually use a “patternLayer” to add a pattern to all of my view controllers. You should resize this in the viewWillLayoutSubviews method.

-(void)viewWillLayoutSubviews {
 
self.patternLayer.frame = self.view.bounds;
[super viewWillLayoutSubviews];
}

Step 5 (if you were a messy coder):

If you have hard coded the height of a view to 460 or 480, you might have to change them all using bounds. For example,

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

instead of

self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

That’s it. You are all set!


Mugunth

 


 

 

반응형