下拉展示动画-医生工作台
效果:

透明色背景
一开始白色View上的文字(箭头处)先显示出来了

参考别的代码,在白色view上添加透明的背景(backView)
必须设置clipsToBounds

动画方法: 修改backView的高度

如果用自动布局,效果是下面这样的,从左上角下来了

不知道为啥是这样
总结: 直接copy代码,仔细对比区别
结论:大的容器view用frame, 里面的细节可以用masonory 明天问问小崔
下面是代码:
// // HDFCheckListAlertView.h // newPatient // // Created by songximing on 16/8/11. // Copyright © 2016年 haodf.com. All rights reserved. // #import <UIKit/UIKit.h> @interface HDFCheckListAlertView : UIView - (instancetype)initWithDoctorName:(NSString *)docName; @property (nonatomic, copy) HDFVoidBlock checkButtonClickBlock; - (void)show; @end
// // HDFCheckListAlertView.m // newPatient // // Created by songximing on 16/8/11. // Copyright © 2016年 haodf.com. All rights reserved. // #import "HDFCheckListAlertView.h" @interface HDFCheckListAlertView () @property (nonatomic, copy) NSString *docName; //!<医生名字 @property (nonatomic, strong) UIView *whiteBgView; //!<背景view @property (nonatomic, strong) UIView *lineView; @property (nonatomic, strong) UIView *backView; @end @implementation HDFCheckListAlertView - (instancetype)initWithDoctorName:(NSString *)docName { if (self = [super initWithFrame:kScreenBounds]) { self.docName = docName; [self configUI]; } return self; } - (void)configUI { self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0]; UIView *lineView = [UIView hdf_viewWithSuperView:self constraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(200); make.right.mas_equalTo(-30); make.width.mas_equalTo(4); make.height.mas_equalTo(20); }]; lineView.backgroundColor = kWColor; self.lineView = lineView; UIButton *closeButton = [UIButton hdf_buttonWithImage:@"" superView:self constraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(lineView.mas_top); make.centerX.mas_equalTo(lineView); make.height.width.mas_equalTo(30); } touchup:^(UIButton *sender) { [self dismiss]; }]; closeButton.backgroundColor = [UIColor redColor]; // 透明色的背景容器 UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(20, 220, kScreenWidth - 40, 0)]; // UIView *backView = [UIView hdf_viewWithSuperView:self constraints:^(MASConstraintMaker *make) { // make.left.mas_equalTo(20); // make.top.mas_equalTo(220); // make.right.mas_equalTo(-20); // make.height.mas_equalTo(0); // }]; backView.backgroundColor = [UIColor clearColor]; backView.clipsToBounds = YES; //!<必须写这句!!!不然没有动画效果 [self addSubview:backView]; self.backView = backView; // 白色的view添加到透明色背景容器上 UIView *whiteBgView = [UIView hdf_viewWithSuperView:backView constraints:^(MASConstraintMaker *make) { make.left.right.top.mas_equalTo(0); make.height.mas_equalTo(200); }]; whiteBgView.backgroundColor = kWColor; self.whiteBgView = whiteBgView; UILabel *titleLabel = [UILabel hdf_labelWithText:[NSString stringWithFormat:@"%@医生为您开具了检查单",self.docName] font:kFontWithSize(16) superView:whiteBgView constraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(20); make.centerX.mas_equalTo(0); }]; UILabel *commentLabel = [UILabel hdf_labelWithText:@"啊哈哈哈哈哈哈(づ ̄3 ̄)づ╭❤~" font:kFontWithSize(14) superView:whiteBgView constraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(30); make.right.mas_equalTo(-30); make.top.mas_equalTo(titleLabel.mas_bottom).offset(25); }]; commentLabel.numberOfLines = 0; kWeakObject(self) UIButton *checkButton = [UIButton hdf_buttonWithTitle:@"查看" superView:whiteBgView constraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(commentLabel.mas_bottom).offset(20); make.left.mas_equalTo(commentLabel); make.right.mas_equalTo(commentLabel); make.height.mas_equalTo(30); } touchup:^(UIButton *sender) { if (weakObject.checkButtonClickBlock) { weakObject.checkButtonClickBlock(); } }]; [checkButton setBackgroundColor:kEssentialColor]; [checkButton setTitleColor:kWColor forState:UIControlStateNormal]; } - (void)dismiss { [self removeFromSuperview]; } -(void)show { [[UIApplication sharedApplication].keyWindow addSubview:self]; // self.backView.height = 0; // [self.backView mas_updateConstraints:^(MASConstraintMaker *make) { // make.height.mas_equalTo(200); // }]; [UIView animateWithDuration:1 animations:^{ self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]; self.backView.height = 200; // [self layoutIfNeeded]; } completion:^(BOOL finished) { }]; } @end
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?