顯示具有 Xcode 標籤的文章。 顯示所有文章
顯示具有 Xcode 標籤的文章。 顯示所有文章

2013年5月15日 星期三

讓iPhone/iPad app icon的名稱有多國語言

昨天有朋友問起這個問題
雖然有看過別人家的app有這樣功能
但是沒自己動手試過

在網路上爬了一下文
做法並不是太困難
重點就是要讓bundle display name這邊可以對應

我是在xcode 4.6.2環境下設定的, 舊一點的版本應該雷同
1. 確定project 底下Supporting Files裡頭有InfoPlist.strings
(別緊張, 一開始應該不會有下拉選單 :P)

注意! 是InfoPlist.strings不是yourapp-Info.plist喔!
而且它是一個string file不是一個property list,
沒有的話自創一個吧~

2. 點一下Project 再選右邊Panel的Project(不是下面的Targets)
3. 然後點選Info的標籤, 下方應該會有個Localizations的區塊


4. 在增加不同國家語言時,會跳出一個視窗問我們兩件事情:
o 一個是default要reference哪個國家的語言設定
o 一個是選擇哪些檔案需要有多國語系檔

5. 完成後應該就會像圖一那樣有下拉選項出現了, 點一個進去看看吧
給"CFBundleDisplayName"一個對應的值.

哇哈哈, 官方連中文版都有文件了, 直接連過去看個仔細吧XD
參考資料: 官方文件, stackoverflow

2012年10月13日 星期六

iOS6 UI rotation issue

Apple does teach me a lesson that I should read the release note first!

If the app is navigation based, you may want to read this:
每個viewcontroller可支援的方向都能彈性調整 ,主要就是參照top-most viewcontroller (root viewcontroller)裡的設定

  • Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method of UIViewController is deprecated. In its place, you should use the supportedInterfaceOrientationsForWindow: and shouldAutorotate methods.
    簡單來說,
     shouldAutorotateToInterfaceOrientation在iOS6失效了,請改用supportedInterfaceOrientationsForWindow: 跟 shouldAutorotate:
    • More responsibility is moving to the app and the app delegate. Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate. By default, an app and a view controller’s supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.
      控制方向旋轉的功能被提升到delegate來作管控,以往什麼self.navigationcontroller 沒辦法一招吃天下啦; 然後iPhone預設不支援頭上腳下的方向,iPad預設則是通通支援.
    • A view controller’s supported interface orientations can change over time—even an app’s supported interface orientations can change over time. The system asks the top-most full-screen view controller (typically the root view controller) for its supported interface orientations whenever the device rotates or whenever a view controller is presented with the full-screen modal presentation style. Moreover, the supported orientations are retrieved only if this view controller returns YES from its shouldAutorotate method. The system intersects the view controller’s supported orientations with the app’s supported orientations (as determined by the Info.plist file or the app delegate’s application:supportedInterfaceOrientationsForWindow: method) to determine whether to rotate.
      iOS6的autorotate方法是給top most view controller來做控管,可以在app delegate裡面透過application:supportedInterfaceOrientationsForWindow:來設定,或是寫在plist裡面;總之支援的方向可以隨時改變甚至是present view都沒問題,只要確定shouldAutorotate的回傳值是YES就對了.
    • The system determines whether an orientation is supported by intersecting the value returned by the app’s supportedInterfaceOrientationsForWindow: method with the value returned by the supportedInterfaceOrientations method of the top-most full-screen controller.
      系統決定app 支援哪些方向是取決於兩個method的交集: supportedInterfaceOrientationsForWindow:跟supportedInterfaceOrientations
    • The setStatusBarOrientation:animated: method is not deprecated outright. However, it now works only if the supportedInterfaceOrientations method of the top-most full-screen view controller returns 0. This puts the responsibility of ensuring that the status bar orientation is consistent into the hands of the caller.
      現在setStatusBarOrientation:animated:是由top-most view controller 來控制, 另外一個條件就是supportedInterfaceOrientations回傳值為0,這樣纔會work.
    • For compatibility, view controllers that still implement the shouldAutorotateToInterfaceOrientation: method do not get the new autorotation behaviors. (In other words, they do not fall back to using the app, app delegate, or Info.plist file to determine the supported orientations.) Instead, the shouldAutorotateToInterfaceOrientation: method is used to synthesize the information that would be returned by the supportedInterfaceOrientations method.
      由於兼容性的關係,所以一旦實作了shouldAutorotateToInterfaceOrientation:這個方法,那app就不會去管delegate或是plist裡面關於autorotation的設定;shouldAutorotateToInterfaceOrientation:這個方法可以視作為supportedInterfaceOrientations的getter&setter function
  • The willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation: methods are no longer called on any view controller that makes a full-screen presentation over itself—for example, by calling presentViewController:animated:completion:.
    這裡提到willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:, didRotateFromInterfaceOrientation:這三個function都不會再有event觸發,所以當present一個viewcontroller之後不能依靠這三個function來更新或是調整layout而是該改用下面的這個viewWillLayoutSubviews
    • You should make sure that your apps are not using these methods to manage the layout of any subviews. Instead, they should use the view controller’s viewWillLayoutSubviews method and adjust the layout using the view’s bounds rectangle.

前面廢話完了,回歸正題
如果app需要用到navigation controller的話:
1. 先check app delegate

1
2
urNavigationCtrl = [[UINavigationController alloc] initWithRootViewController:viewController];
[window addSubview:urNavigationCtrl.view];

改成

1
2
3
urNavigationCtrl = [[UINavigationController alloc] init];
[urNavigationCtrl pushViewController:firstViewCtrl animated:NO];
self.window.rootViewController = urNavigationCtrl;

2. 參照aprato在stackoverflow的解答, 我們需要Category來解決使用加了navigation controller之後的後遺症.在第一個view的.m裡面加上這段code


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
@implementation UINavigationController (Rotation_IOS6)

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

@end

3. 然後在每一個需要overwrite的頁面重新define自己想要的行為, for example:

1
2
3
4
5
6
7
- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

資料來源:9to5mac, disanji.net, roostersoftstudios


2010年11月8日 星期一

iPhone can't change language of Xcode

寫程式或許會遇到丈二金剛摸不著頭緒的時候
debug可能會嚐到眼花撩亂頭暈目眩的情形
但是當你碰上Xcode的build setting語言改不掉


一開始會很火大…
阿不就系統設定(system preference)裡面
語言與文字選項(language and text)順序調整一下
再不然,狠一點從list上面移除

再來會很無奈
重開Xcode,登出登入,重開機,無濟於事阿!!!

最後會掉入絕望的深淵
只能看著像是外星來的語言
冒著error,warning無情的嘲弄
猜測屬性的設定,這邊試試看,那邊試試看

不是我歧視日文,而是真的完全看不懂阿
不能這樣溫良恭儉讓下去了~
好不容易我找到了大絕招,這樣做就對了!

1. 首先找到Developer -> Application -> Xcode
2. Ctrl + click -> Show Package Contents -> Resource
3. 把那個叫Japanese.lproj 整個砍了吧!!

重新開啟Xocde,迎接清爽的build setting page吧 :)

資料來源: macosx.com

內容回應