MBProgressHUD 顯示方向異常,mbprogresshud方向

來源:互聯網
上載者:User

MBProgressHUD 顯示方向異常,mbprogresshud方向

一直在iphone上使用MBProgressHUD做提示資訊視圖,一直都沒有什麼問題,但用在ipad上使用時,卻有時會出現顯示方向不正常,如ipad螢幕是橫的,但當MBProgressHUD出現時卻按照豎屏的方向進行顯示,一直不解,仔細看了出現的情況,發現有2種情況會出現方向異常:1.用 presentViewController 出來的控制器,且方向固定,方向與裝置方向不一致。2.當UIAlerView和MBProgressHUD一起出現的時候。

我們初始化MBProgressHUD時可能會用到下面方式初始化

[cpp] view plaincopy
  1. UIWindow *window = [[UIApplication sharedApplication] keyWindow];  
  2. _hud = [[MBProgressHUD alloc] initWithWindow:window];  

但是當UIAlertView出現時會重新初始化一個UIWindow並設定為keyWindow,這時當使用[[UIApplication shareApplication] keyWindow] 時擷取到的就不是你本意想拿到的應用程式的UIWindow,另外UIAlertView的UIWindow方向可能就不是橫屏的了,所以才出現以上的情況;

解決:使用 

_hud = [[MBProgressHUD alloc] initWithView:view];

初始化就行了

還有另一種情況

當你在UIAlertView委託方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;用第一種方法顯示(即需要擷取keyWindow),還是不能擷取到主程式的keyWindow,

解決方案 用另一個委託就可以了

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;

以上親測沒有問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.