iphone弹出窗口效果的制作(Core animation, CALayer)
2014-04-29 17:31
525 查看
效果类似人人网微薄客户端的弹出效果
如果想实现圆角的视图:
// 如果在层上添加的视图如图片比父视图大,应该试用maskToBounds = YES;
static CGFloat kTransitionDuration = 0.3; - (void)initView { UIWindow *window = [UIApplication sharedApplication].keyWindow; if (!window) { window = [[UIApplication sharedApplication].windows objectAtIndex:0]; } _backgroundView = [[UIView alloc] initWithFrame:window.bounds]; // 这个可以使背景变成灰色,类似UIAlertView弹出的效果 _backgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.35]; // 叠加到window上,这样他的父窗口就无法再响应点击消息了. [window addSubview:_backgroundView]; self.frame = CGRectMake(10, 60, 300, 380); [_backgroundView addSubview:self]; self.backgroundColor = [UIColor orangeColor]; // 一系列动画效果, 先放大0.1, 在缩小0.1,随后还原原始大小,达到反弹效果 self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.05, 0.05); [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:kTransitionDuration/1.5]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(bounceAnimationStopped)]; self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1); [UIView commitAnimations]; } - (void)bounceAnimationStopped { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:kTransitionDuration/2]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(bounce2AnimationStopped)]; self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9); [UIView commitAnimations]; } - (void)bounce2AnimationStopped { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:kTransitionDuration/2]; self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0); [UIView commitAnimations]; }
如果想实现圆角的视图:
CALayer *subLayer = [CALayer layer]; subLayer.backgroundColor = [UIColor whiteColor].CGColor; subLayer.shadowOffset = CGSizeMake(0, 10); subLayer.shadowRadius = 5.0; subLayer.shadowColor = [UIColor blackColor].CGColor; subLayer.shadowOpacity = 0.8; subLayer.frame = CGRectMake(30, 30, 150, 190); subLayer.cornerRadius = 10; subLayer.borderColor = [[UIColor blackColor] colorWithAlphaComponent:0.75].CGColor; subLayer.borderWidth = 4; [self.layer addSublayer:subLayer];
// 如果在层上添加的视图如图片比父视图大,应该试用maskToBounds = YES;
相关文章推荐
- C++虚函数和纯虚函数的区别
- Qt多线程编程中的对象线程与函数执行线程
- 《面试题精选》16.双栈实现队列和双队列实现栈
- 浅谈mmap()
- gcc 的gimple 调试
- 如何正确配置Nginx+PHP及正确的nginx URL重写
- 注册表添加多级菜单
- 服务器(Server)
- 应用collect,
- 花草摆放
- Ubuntu12.04安装YouCompleteMe等相关插件 (已附上我现在用的完整.vimrc配置文件)
- NX二次开发 克隆
- [openstack]卸载卷(detach volume)流程
- 传值&传引用&传指针
- 从VGA到GPU!细数二十年显卡发展历程
- 从VGA到GPU!细数二十年显卡发展历程
- IE兼容性视图,新增元素导致白页面
- 从VGA到GPU!细数二十年显卡发展历程
- sencha touc 一个页面不同调用注意问题
- 三维模型2.5D轮廓提取及遮挡部分的剔除