UIwindows 提示框动画显示以及隐藏关闭

本文介绍了一种在 iOS 应用中实现自定义弹窗视图的方法,包括创建悬浮窗口、设置按钮响应及动画效果等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近做弹出相册选择等的弹出框,自己做了一个。互相学习一下。。。

直接上代码

@property (strong,nonatomic) UIWindow *windowButtonMineView;//悬浮


#pragma mark 修改图像响应方法

- (void)btnUserImageClick:(UIButton *)sender {


    _windowButtonMineView = [[UIWindow alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 140)];

    _windowButtonMineView.windowLevel = UIWindowLevelAlert;

    //_windowButton.backgroundColor = [UIColor colorWithRed:233 green:233 blue:233 alpha:1.0];

    _windowButtonMineView.backgroundColor = ColorViewBackground;

    

    float btnWidth = _windowButtonMineView.frame.size.width,btnHeigth = 40;

    UIButton *btnEditImage1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 1, btnWidth, btnHeigth)];

    [btnEditImage1 setTitle:@"拍照" forState:UIControlStateNormal];

    [btnEditImage1 setTitleColor:ColorTextFondColor forState:UIControlStateNormal];

    btnEditImage1.backgroundColor = [UIColor whiteColor];

    btnEditImage1.tag = 2;

    [btnEditImage1 addTarget:self action:@selector(btnImageBackClickInMineView:) forControlEvents:UIControlEventTouchUpInside];

    [_windowButtonMineView addSubview:btnEditImage1];

    

    UIButton *btnEditImage2 = [[UIButton alloc] initWithFrame:CGRectMake(0, 42, btnWidth, btnHeigth)];

    [btnEditImage2 setTitle:@"从手机相册选择" forState:UIControlStateNormal];

    [btnEditImage2 setTitleColor:ColorTextFondColor forState:UIControlStateNormal];

    btnEditImage2.backgroundColor = [UIColor whiteColor];

    btnEditImage2.tag = 1;

    [btnEditImage2 addTarget:self action:@selector(btnImageBackClickInMineView:) forControlEvents:UIControlEventTouchUpInside];

    [_windowButtonMineView addSubview:btnEditImage2];

    

    

    UIButton *btnEditImage4 = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, btnWidth, btnHeigth)];

    btnEditImage4.backgroundColor = [UIColor whiteColor];

    [btnEditImage4 setTitle:@"取消" forState:UIControlStateNormal];

    [btnEditImage4 setTitleColor:ColorTextFondColor forState:UIControlStateNormal];

    [btnEditImage4 addTarget:self action:@selector(BtnCloseImageWindowsInMineView) forControlEvents:UIControlEventTouchUpInside];

    [_windowButtonMineView addSubview:btnEditImage4];

    

    

    //显示window

    [_windowButtonMineView makeKeyAndVisible];

    

    

    

    //设置动画的名字

    [UIView beginAnimations:@"Animation" context:nil];

    //设置动画的间隔时间

    [UIView setAnimationDuration:0.50];

    //??使用当前正在运行的状态开始下一段动画

    [UIView setAnimationBeginsFromCurrentState: YES];

    //设置视图移动的位移

    _windowButtonMineView.frame = CGRectMake(0, self.view.frame.size.height-140, self.view.frame.size.width, 140);

    //设置动画结束

    [UIView commitAnimations];


}



#pragma mark 关闭windows视图

-(void)BtnCloseImageWindowsInMineView{

    //关闭UIwindow

    [self performSelector:@selector(scale_1) withObject:nil afterDelay:0.0f];

    [self performSelector:@selector(scale_2) withObject:nil afterDelay:0.5f];

}

//以下是启动页动画效果

-(void)scale_1

{

    //设置动画的名字

    [UIView beginAnimations:@"Animation" context:nil];

    //设置动画的间隔时间

    [UIView setAnimationDuration:0.50];

    //??使用当前正在运行的状态开始下一段动画

    [UIView setAnimationBeginsFromCurrentState: YES];

    //设置视图移动的位移

    _windowButtonMineView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 140);

    //设置动画结束

    [UIView commitAnimations];

}


-(void)scale_2

{

    //关闭UIwindow

    _windowButtonMineView.hidden = YES;

    [_windowButtonMineView resignKeyWindow];

    _windowButtonMineView = nil;

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值