首页 > 移动平台 > 详细

ios 中的半屏幕底部弹出框

时间:2015-03-06 18:31:17      阅读:2478      评论:0      收藏:0      [点我收藏+]
static UIView *modalView;
if
(modalView) { [modalView removeFromSuperview]; modalView = nil; return; } CGRect screen = [[UIScreen mainScreen] bounds]; CGRect bounds = CGRectMake(screen.origin.x, screen.origin.y, screen.size.width, screen.size.height/2); modalView = [[UIView alloc] initWithFrame:bounds]; modalView.opaque = NO; modalView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f]; UILabel *label = [[UILabel alloc] init]; label.text = @"Modal View"; label.textColor = [UIColor whiteColor]; label.backgroundColor = [UIColor clearColor]; label.opaque = NO; [label sizeToFit]; [label setCenter:CGPointMake(modalView.frame.size.width / 2, modalView.frame.size.height / 2)]; [modalView addSubview:label]; [self.view addSubview:modalView];

 

若要从xib众加载UI的外观,则:

if (popupViewController) {
        [popupViewController.view removeFromSuperview];
        popupViewController = nil;
        return;
    }
    
    popupViewController = [[UIViewController alloc] initWithNibName:@"View" bundle:nil];
    [self.view addSubview:popupViewController.view];

 

如果需要从底部的动画向上slide in的动画:

UIView *popView = popupViewController.view;
    CGRect orig = popView.bounds;
    CGRect screen = [[UIScreen mainScreen] bounds];
    [popView setFrame:CGRectMake(0, screen.size.height, orig.size.width, orig.size.height)];
    [UIView beginAnimations:@"animatePopView" context:nil];
    [UIView setAnimationDuration:0.4];
    [popView setFrame:CGRectMake(0, screen.size.height-orig.size.height, orig.size.width, orig.size.height)];
    [UIView commitAnimations];

 

ios 中的半屏幕底部弹出框

原文:http://www.cnblogs.com/welhzh/p/4318756.html

(1)
(2)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!