POP弹性动画效果
来源:互联网 发布:淘宝客开发论坛 编辑:程序博客网 时间:2024/05/19 03:28
1.中间的彩色按钮是用POP做的弹性动画依次下落到指定位置,并有弹簧效果
2.彩色Button为自定义button
3.透明背景为自定义window,在modal情况下,覆盖的控制器会被移除,在dismiss时重新添加,因此改为添加一个新的窗口;
4.在移除动画时,用block回调,执行按钮点击后的操作
#import "ZHPublicView.h"
#import <POP.h>
#import "ZHbutton.h"
@implementation ZHPublicView
//点击底部加号按钮,对外接口方法
+(void)show{
UIView *publicView = [[[NSBundlemainBundle]loadNibNamed:NSStringFromClass(self)owner:niloptions:nil]firstObject];
publicView.frame = window_.bounds;
[window_ addSubview:publicView];
}
static UIWindow *window_;
//一次性操作
-(void)awakeFromNib{
window_ = [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];
window_.backgroundColor = [[UIColorwhiteColor]colorWithAlphaComponent:0.8];
window_.hidden =NO;
self.userInteractionEnabled =NO;
[selfsetUptext];
[selfaddAllChildButton];
}
//添加子控件,图片为本地bundle图片
-(void)addAllChildButton{
NSArray *title =@[@"发视频",@"发图片",@"发段子",@"发声音",@"审帖",@"离线下载"];
NSArray *image =@[@"publish-video",@"publish-picture",@"publish-text",@"publish-audio",@"publish-review",@"publish-offline"];
//按钮的frame
NSInteger col = 3;
CGFloat margin = 10;
CGFloat buttonW = 80;
CGFloat buttonH = 100;
CGFloat marginX = ([UIScreenmainScreen].bounds.size.width -2 * margin - col * buttonW) / 2;
CGFloat beginY = [UIScreenmainScreen].bounds.size.height *0.5 - buttonH;
for (NSInteger i =0; i < 6; i++) {
CGFloat x = margin + (buttonW + marginX)*(i % col);
CGFloat y = beginY + (buttonH + margin)*(i / col);
ZHbutton *button = [ZHbuttonbuttonWithType:UIButtonTypeCustom];
button.tag = i;
[button addTarget:selfaction:@selector(buttonClick:)forControlEvents:UIControlEventTouchUpInside];
[button setTitle:title[i]forState:UIControlStateNormal];
[button setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
CGRect beginFrame = CGRectMake(x, y - 375, buttonW, buttonH);;
CGRect endFrame = CGRectMake(x, y, buttonW, buttonH);
button.frame = endFrame;
[button setImage:[UIImageimageNamed:image[i]] forState:UIControlStateNormal];
[self addSubview:button];
//POP动画
POPSpringAnimation *spring = [POPSpringAnimationanimationWithPropertyNamed:kPOPViewFrame];
spring.fromValue = [NSValuevalueWithCGRect:beginFrame];
spring.toValue = [NSValuevalueWithCGRect:endFrame];
spring.springBounciness = 12;
spring.springSpeed = 8;
spring.beginTime = CACurrentMediaTime() + 0.05 * i;
[button pop_addAnimation:spring forKey:nil];
}
}
-(void)cancelButtonWithCompleBlock:(void (^)())completion{
for (int i =1; i < self.subviews.count; i++) {
UIView *subView = self.subviews[i];
POPBasicAnimation *spring = [POPBasicAnimationanimationWithPropertyNamed:kPOPViewCenter];
CGFloat centerY = [UIScreenmainScreen].bounds.size.height + subView.ZH_Y;
spring.toValue = [NSValuevalueWithCGPoint:CGPointMake(subView.ZH_centerX, centerY)];
spring.beginTime = CACurrentMediaTime() + i * 0.1;
[subView pop_addAnimation:spring forKey:nil];
if (i == self.subviews.count -1) {
[spring setCompletionBlock:^(POPAnimation *anima,BOOL comple) {
window_.hidden =YES;
window_ = nil;
!completion ? :completion();
}];
}
}
}
-(void)buttonClick:(UIButton *)button{
[selfcancelButtonWithCompleBlock:^{
NSLog(@"%ld",button.tag);//点击按钮操作事件
}];
}
-(void)setUptext{
UIImageView *imageView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"app_slogan"]];
[self addSubview:imageView];
POPSpringAnimation *spring = [POPSpringAnimationanimationWithPropertyNamed:kPOPViewCenter];
CGFloat centerX = [UIScreenmainScreen].bounds.size.width *0.5;
CGFloat centerY = [UIScreenmainScreen].bounds.size.height *0.2;
spring.fromValue = [NSValuevalueWithCGPoint:CGPointMake(centerX , centerY -200)];
spring.toValue = [NSValuevalueWithCGPoint:CGPointMake(centerX, centerY)];
spring.springBounciness =20;
spring.springSpeed = 18;
spring.beginTime = CACurrentMediaTime() + 6 * 0.05;
[spring setCompletionBlock:^(POPAnimation * anima,BOOL complish) {
self.userInteractionEnabled =YES;
}];
[imageView pop_addAnimation:spring forKey:nil];
}
- (IBAction)cancelButton{
[selfcancelButtonWithCompleBlock:nil];
}
@end
#import <UIKit/UIKit.h>
@interface ZHPublicView : UIView
+(void)show;
@end
/////////////////////////////自定义button
#import "ZHbutton.h"
@implementation ZHbutton
-(void)layoutSubviews{
[superlayoutSubviews];
self.imageView.ZH_Y =0;
self.imageView.ZH_centerX =self.ZH_Width *0.5;
self.titleLabel.ZH_Y =self.imageView.ZH_Height +3;
[self.titleLabelsizeToFit];
self.titleLabel.ZH_centerX =self.ZH_Width *0.5;
}
@end
- POP弹性动画效果
- css弹性动画效果
- pop 阻尼动画效果
- andorid上拉下拉弹性动画效果
- QQ中的弹性球动画效果
- Swift 组合动画效果(JNW、POP)
- 弹性动画
- 弹性动画
- 弹性动画
- 弹性动画
- 弹性效果
- 布局 html5手机端果冻弹性菜单动画效果代码
- pop动画
- pop动画
- iOS pushViewController 实现push 和pop 默认动画效果
- iOS 动画效果:Core Animation & Facebook's pop
- iOS 动画效果:Core Animation & Facebook's pop
- Objective-C改变push、pop动画为模态效果
- MAC OS 配置android环境
- 白话经典算法系列之六 快速排序 快速搞定
- 2016年3月小结
- 自定义dialog的宽度充满整个屏幕宽度的问题
- 进程,线程之间易混淆的几个问题
- POP弹性动画效果
- 获取手机总内存以及格式转化
- OpenCV学习- 配置
- Java笔记---CenOS下配置Java开发环境(OpenJDK+Tomcat8)
- py-faster-rcnn + ZF 实现自己的数据训练与检测(二)
- BBC: 寨卡病毒威胁美国,国际空间站宇航员返回地球
- Spinner使用
- codeforces 451 E Devu and Flowers
- 白盒测试-百度出来的感觉说的还是蛮详细的