簡體   English   中英

無論屏幕方向如何,iPhone中心活動指示器

[英]iPhone center activity indicator regardless of screen orientation

無論屏幕方向如何,我如何以編程方式居中設置活動指示器?

嘗試設置活動視圖的center屬性,如下所示:

 activity.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);

viewDidLoad ,注冊設備輪換的通知:

- (void)viewDidLoad {
   [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
   [[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(didRotate:)
        name:UIDeviceOrientationDidChangeNotification object:nil];
}

並實現didRotate:

-(void)didRotate:(NSNotification *)notification {   
   if (activity) {
    activity.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);
    }
}

我建議你使用https://github.com/jdg/MBProgressHUD這是一個很棒的庫,用於做各種“加載”屏幕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM