發表文章

目前顯示的是 12月, 2011的文章

iOS View不會隨著機子旋轉

翻轉螢幕後VIEW無法跟著同步旋轉的問題 有時是重繪問題 有時是VIEW繼承問題 我的tabbar有多个tabview,当我进行旋转的时候,当前的view能够接受到旋转事件,但其他几个view无法接受到,导致我切换view时其他view的rect还是原大小,不知道该如何解决呢? 翻轉螢幕會觸發shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation與willAnimateRotationToInterfaceOrientation事件 可在事件裡面增加: [self.viewController willAnimateRotationToInterfaceOrientation: toInterfaceOrientation duration:duration]; 如果是選轉後大小跑掉可以在在shouldAutorotateToInterfaceOrientation重設 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 重設你的元件大小或是設定 return YES; } 另外一種View不會選轉的可能性 參考[1]   在UIWindow中添加了兩個ViewController,並顯示後一個ViewController的視圖,結果視圖並沒有被旋轉成橫版,仍舊按照豎版來顯示。Google和StackOverFlow了一把,發現很多人都碰到過類似的問題,比如這個和這個。當然也有人給出了解決方案:給UIWindow設置一個rootViewController,爾後添加的所有ViewController都以rootViewController的subview形式添加。 See Also: iOS View事件處理流程 什么样的UIViewController具有响应屏幕旋转事件的权限 

使用程式判斷目前使用的機型是IPHONE還是IPAD

t ypedef enum  { #if __IPHONE_3_2 <= __IPHONE_OS_VERSION_MAX_ALLOWED     UIUserInterfaceIdiomPhone,            // iPhone and iPod touch style UI     UIUserInterfaceIdiomPad,              // iPad style UI #endif } UIUserInterfaceIdiom; /* The UI_USER_INTERFACE_IDIOM() macro is provided for use when deploying to a version of the iOS less than 3.2. If the earliest version of iPhone/iOS that you will be deploying for is 3.2 or greater, you may use -[UIDevice userInterfaceIdiom] directly.  */ #define UI_USER_INTERFACE_IDIOM() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone) UIDevice的property userInterfaceIdiom The style of interface to use on the current device. (read-only) @property (nonatomic, readonly)   UIUserInterfaceIdiom userInterfaceIdiom 在AppDelegate裡,通過獲取UIDevice的user...

IOS Objective-C JSON Parse轉成Dictionary

IOS5後支援的功能 Parse json object into a dic      - (  void  ) fetchedData: (NSData *) responseData {  / / Parse out the JSON dataNSError * Error;        NSDictionary * json = [NSJSONSerialization            JSONObjectWithData: responseData   / / 1                options: kNilOptions            error: & error];           NSArray * latestLoans = [JSON objectForKey: @  "loans"  ];   / / 2            NSLog (@  "loans:% @"  , latestLoans);   / / 3    }      Generate json string to object   / / Build an info object and convert to json    NSDictionary * i...

資策會DAY2

圖片
上班第二天 接手兩隻程式 跑一下analyze... 看來要修BUG一段時間了