Ios 在iPhone 6+;
我有以下代码:Ios 在iPhone 6+;,ios,objective-c,iphone-6-plus,Ios,Objective C,Iphone 6 Plus,我有以下代码: UIWindow* window = [[[UIApplication sharedApplication].windows sortedArrayUsingComparator:^NSComparisonResult(UIWindow *win1, UIWindow *win2) { return win1.windowLevel - win2.windowLevel; }] lastObject]; NSString* labelText =
UIWindow* window = [[[UIApplication sharedApplication].windows sortedArrayUsingComparator:^NSComparisonResult(UIWindow *win1, UIWindow *win2) {
return win1.windowLevel - win2.windowLevel;
}] lastObject];
NSString* labelText = self.message;
NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:17.0f]};
CGRect rect = [labelText boundingRectWithSize:CGSizeMake(500.0f, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributes
context:nil];
CGSize labelSize = rect.size;
float viewWidth = labelSize.width+20;
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake((window.bounds.size.width-viewWidth)/2, window.bounds.size.height/2.5, viewWidth, 30)];
label.alpha = 0;
[window addSubview:label];
label.textAlignment = NSTextAlignmentCenter;
label.backgroundColor =[UIColor blackColor];
label.textColor = [UIColor whiteColor];
label.text = labelText;
label.layer.cornerRadius = 15;
label.layer.masksToBounds = YES;
[UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionCurveEaseIn animations:^{
label.alpha = 0.9;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1.0f delay:self.duration options:UIViewAnimationOptionCurveEaseOut animations:^{
label.alpha = 0;
} completion:^(BOOL finished) {
[label removeFromSuperview];
}];
}];
在iPhone 5和iPhone 6中,UILabel在执行上一个代码后立即显示,但在iPhone 6 plus中,它在屏幕上显示之前需要5秒钟,这很奇怪,这段代码有什么问题?这段代码在主线程上执行吗?@MichaelL yes,在主线程上