在您的.m文件中添加#import <QuartzCore/QuartzCore.h>
框架并使用以下代码
UIWindow* window = [UIApplication sharedApplication].keyWindow;
self.dimView = [[UIView alloc] initWithFrame:window.bounds];
self.dimView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.6];
self.dimView.userInteractionEnabled = YES;
[window addSubview:self.dimView];
上面这个是透明的dimView,大小和window差不多。
self.searchTblContainerView = [[UIView alloc] init];
self.searchTblContainerView.frame = CGRectMake(15, (window.frame.size.height - 300) / 2, 290, 300);
self.searchTblContainerView.layer.cornerRadius = 15.f;
self.searchTblContainerView.layer.borderColor = [UIColor blackColor].CGColor; /// set color as per your requirement
self.searchTblContainerView.layer.borderWidth = 2.f;
self.searchTblContainerView.alpha = 0.80; /// set as per your requirement
self.searchTblContainerView.clipsToBounds = YES;
[self.dimView addSubview:self.searchTblContainerView];
以上self.searchTblContainerView
是包含您的整体的主视图,UIControls
例如标签、文本字段、按钮等...并根据您的要求进行设置。
默认设置 hidden 属性,self.dimView.hidden = YES;
并通过alertView (apple)等动画进行显示和隐藏。
以下代码用于显示 dimView。
self.searchTblContainerView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.30 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.searchTblContainerView.transform = CGAffineTransformIdentity;
self.dimView.hidden = NO;
} completion:^(BOOL finished){}];
UIWindow* window = [UIApplication sharedApplication].keyWindow;
[window bringSubviewToFront:self.dimView];
以下代码用于隐藏 dimView。
self.searchTblContainerView.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:0.30 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.searchTblContainerView.transform = CGAffineTransformMakeScale(0.01, 0.01);
} completion:^(BOOL finished){
self.dimView.hidden = YES;
}];
上面的代码是简单的逻辑,可能对您的情况有用。