[英]Activity indicator not centered in landscape mode
我試圖在表格視圖的頂部添加一個活動指示器,以使其在縱向和橫向模式下都出現在屏幕的中央。
活動指示器放置在視圖內部,該視圖是主視圖的子視圖。 表格視圖通過視圖容器包含在主視圖中。
當我單擊“添加缺少的約束”時,指示器將獲得中心Y對齊約束和水平空間(141)約束。 正如預期的那樣,在縱向模式下,一切看起來都很好,但是在橫向模式下,活動指示器顯示在左側,而不是水平居中。
我試圖將“水平空間”約束更改為“中心X”對齊約束,但這似乎並沒有使情況變得更好。
有什么建議么?
這是一個特寫:
->首先,添加Spinner View(屏幕截圖中的黃色)
選擇它並按如下所示設置約束
將其固定到所有四個邊緣
->其次添加活動指示器。
選擇它並按如下所示設置約束
中心X和中心Y = 0
如果存在任何視圖放錯的警告,請選擇“解決自動布局問題”!
最后,約束看起來像這樣
如果要以編程方式執行此操作,則在控制器類中:
self.activityIndicatorObject.center = self.view.center;
編輯:
也許你可以試試這個:
self.activityIndicatorObject.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2.0, [UIScreen mainScreen].bounds.size.height/2.0);
SWIFT 3.2
嘗試這個
self.activityIndicator.center = CGPoint(x:self.view.bounds.size.width/2.0,y: self.view.bounds.size.height/2.0);
activityIndicator.autoresizingMask = (UIViewAutoresizing(rawValue: UIViewAutoresizing.RawValue(UInt8(UIViewAutoresizing.flexibleRightMargin.rawValue) | UInt8(UIViewAutoresizing.flexibleLeftMargin.rawValue) | UInt8(UIViewAutoresizing.flexibleBottomMargin.rawValue) | UInt8(UIViewAutoresizing.flexibleTopMargin.rawValue))))
看一下你的constraints
。 似乎您需要在微調器視圖上進行center x alignment
。
編輯
為了節省一些令人困惑的約束問題,建議您以編程方式放置微調器。 您可以在表視圖加載時禁用它,並將userInteractionEnabled
設置為NO
。
// Set up your spinner
UIActivityIndicatorView * spinner = [[UIActivityIndicatorView alloc] init];
[spinner setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
[spinner setHidesWhenStopped:YES];
[spinner setCenter:self.view.center];
[spinner startAnimating];
[self.view addSubview:spinner];
// disable your tableView
tableView.userInteractionEnabled = NO;
我已通過情節提要添加了活動指標並分配
它在縱向和橫向模式下在屏幕中央顯示指示器。 請嘗試這個。 希望對你有效。 謝謝
Your constraints are having problem, i have done the same thing in sample,
please take a look and try to set constraints accordingly,
it would fix the problem. I have attached a snapshot for constraints.
僅代碼約束問題中沒有其他問題。 祝好運。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.