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

来源:互联网 发布:网络语香菇是什么意思 编辑:程序博客网 时间:2024/05/22 14:32

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

直接上代码

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


#pragma mark 修改图像响应方法

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


    _windowButtonMineView = [[UIWindowalloc] 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 = [[UIButtonalloc] initWithFrame:CGRectMake(0,1, btnWidth, btnHeigth)];

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

    [btnEditImage1 setTitleColor:ColorTextFondColorforState:UIControlStateNormal];

    btnEditImage1.backgroundColor = [UIColorwhiteColor];

    btnEditImage1.tag =2;

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

    [_windowButtonMineViewaddSubview:btnEditImage1];

    

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

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

    [btnEditImage2 setTitleColor:ColorTextFondColorforState:UIControlStateNormal];

    btnEditImage2.backgroundColor = [UIColorwhiteColor];

    btnEditImage2.tag =1;

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

    [_windowButtonMineViewaddSubview:btnEditImage2];

    

    

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

    btnEditImage4.backgroundColor = [UIColorwhiteColor];

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

    [btnEditImage4 setTitleColor:ColorTextFondColorforState:UIControlStateNormal];

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

    [_windowButtonMineViewaddSubview:btnEditImage4];

    

    

    //显示window

    [_windowButtonMineViewmakeKeyAndVisible];

    

    

    

   //设置动画的名字

    [UIViewbeginAnimations:@"Animation"context:nil];

   //设置动画的间隔时间

    [UIViewsetAnimationDuration:0.50];

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

    [UIViewsetAnimationBeginsFromCurrentState: YES];

   //设置视图移动的位移

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

    //设置动画结束

    [UIViewcommitAnimations];


}



#pragma mark 关闭windows视图

-(void)BtnCloseImageWindowsInMineView{

    //关闭UIwindow

    [selfperformSelector:@selector(scale_1)withObject:nilafterDelay:0.0f];

    [selfperformSelector:@selector(scale_2)withObject:nilafterDelay:0.5f];

}

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

-(void)scale_1

{

   //设置动画的名字

    [UIViewbeginAnimations:@"Animation"context:nil];

   //设置动画的间隔时间

    [UIViewsetAnimationDuration:0.50];

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

    [UIViewsetAnimationBeginsFromCurrentState: YES];

   //设置视图移动的位移

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

    //设置动画结束

    [UIViewcommitAnimations];

}


-(void)scale_2

{

    //关闭UIwindow

    _windowButtonMineView.hidden =YES;

    [_windowButtonMineViewresignKeyWindow];

    _windowButtonMineView =nil;

}



0 0
原创粉丝点击