0

我有一个将 UIActivityIndi​​cator 添加到指定视图的类。我想在给定视图中居中 UIActivityIndi​​cator。

我认为这可以正常工作,因为 UIActivityIndi​​cator 在屏幕上的时间不长。现在我看到当我在他处于活动状态时旋转屏幕时, UIActivityIndi​​cator 不再居中。

我这样做的方式是:

CGRect frame = CGRectMake((view.frame.size.width / 2 - self.activityIndicator.frame.size.width / 2),
                          (view.frame.size.height / 2 - self.activityIndicator.frame.size.height / 2),
                          self.activityIndicator.frame.size.width,
                          self.activityIndicator.frame.size.height
                         );

那么这会产生更好的结果:

self.activityIndicator.center = view.center;

有什么方法可以添加一个约束,这样即使旋转它也能保持在中间。我知道这可以在 IB 中完成,但在代码中我不知道?

4

1 回答 1

3

您的代码,加上:

self.activityIndicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin);
于 2013-11-08T15:37:21.367 回答