我扩展了UIView
类以创建重叠加载屏幕。
FullLoadingView.h
#import <UIKit/UIKit.h>
@interface FullLoadingView : UIView
+ (instancetype)showOnView:(UIView *)view;
+ (void)hideAll:(UIView *)view;
- (void)hide;
@end
FullLoadingView.m
#import "FullLoadingView.h"
@implementation FullLoadingView
+ (instancetype)showOnView:(UIView *)view
{
FullLoadingView *fullLoadingView = [[self alloc] init];
[fullLoadingView setFrame:view.bounds];
[fullLoadingView setBackgroundColor:[UIColor colorWithRed:(250.0/255.0) green:(250.0/255.0) blue:(250.0/255.0) alpha:1.0]];
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicatorView.center = fullLoadingView.center;
[activityIndicatorView startAnimating];
[view addSubview:fullLoadingView];
return fullLoadingView;
}
- (void)hide
{
[self removeFromSuperview];
}
+ (void)hideAll:(UIView *)view
{
NSEnumerator *subviewsEnum = [view.subviews reverseObjectEnumerator];
for (UIView *subview in subviewsEnum) {
if ([subview isKindOfClass:self]) {
FullLoadingView *fullLoadingView = (FullLoadingView *)subview;
[fullLoadingView removeFromSuperview];
}
}
}
@end
UIViewController代码:
- (void)viewDidLoad {
FullLoadingView *fullLoadingView = [FullLoadingView showOnView:self.view];
}
问题:
当UIViewController
有NavigationBar
或TabBar
UIActivityIndicatorView
的中心对齐方式不正确时。
PS:self.view
的高度正确(NavigationBar
或TabBar
除外),但FullLoadingView
始终具有设备的完整高度。
答案 0 :(得分:2)
您在fullLoadingView
中创建了viewDidLoad
,但self.view
之前的viewDidLayoutSubviews
帧不保证对当前设备正确。autoresizingMask
。
最简单的解决方法可能是使用+ (instancetype)showOnView:(UIView *)view
{
FullLoadingView *fullLoadingView = [[self alloc] init];
fullLoadingView.frame = view.bounds;
fullLoadingView.autoresizingMask = (
UIViewAutoresizingFlexibleWidth
| UIViewAutoresizingFlexibleHeight);
fullLoadingView.backgroundColor = [UIColor colorWithRed:(250.0/255.0) green:(250.0/255.0) blue:(250.0/255.0) alpha:1.0];
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicatorView.center = fullLoadingView.center;
activityIndicatorView.autoresizingMask = (
UIViewAutoresizingFlexibleTopMargin
| UIViewAutoresizingFlexibleBottomMargin
| UIViewAutoresizingFlexibleLeftMargin
| UIViewAutoresizingFlexibleRightMargin);
[fullLoadingView addSubview:activityIndicatorView];
[activityIndicatorView startAnimating];
[view addSubview:fullLoadingView];
return fullLoadingView;
}
来保持帧同步:
awk '{for(n=1;n<=NF;n++)print $n>"File"n}' input.txt