2012年8月25日 星期六

UIActionSheet Button location Error

之前一直為了UIActionSheet產生的button位置歪掉煩惱
像這張圖這樣

因為是小問題,所以沒有很認真去查
但實際上又是很煩惱的問題
今天終於搞定了
一般來說 我們要加入一個UIActionSheet會用以下程式碼
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                             delegate:self
                    cancelButtonTitle:NSLocalizedString(@"Cancel", @"Cancel")
               destructiveButtonTitle:NSLocalizedString(@"Logout", @"logout")
                    otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[actionSheet showInView:self.view];
關鍵在最後一行
[actionSheet showInView:self.view];

實際上應該使用
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
要以整個window來看才正確 以上

沒有留言:

張貼留言