前言: 哇喔从题目是不是看出了什么端倪, 没错我打算要造好多好多POP小轮子, 今天是轮子01 , 演示图片我也是挑了好久呢, 博主真是用心呢, 中午空闲时间发出来, 没午睡好困, 扯得有点多~
小轮子01的用途, 可以做提示窗, 也在很多直播的App中比较常见, 尾巴会放出实例工程.
创建继承于UIView的XTPopingView 暂时没做更多功能, 可以实现 下-下 上-下 两种 来看看如何实现吧
声明: 使用Facebook POP了.
1.初始化
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
[self addSubview:self.flyView];
UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClickAction)];
[self addGestureRecognizer:tapGes];
}
return self;
}
- (UIView *)flyView
{
if (!_flyView) {
_flyView = [[UIView alloc] init];
}
return _flyView;
}
2. 开始视图
- (void)startFly:(FlyType)type
{
switch (type) {
case FlyTypeUToD:
{
_flyView.frame = CGRectMake(SCREEN_WIDTH_XT / 2 - self.fly_w / 2, -self.fly_h, self.fly_w, self.fly_h);
}
break;
case FlyTypeDToD:
{
_flyView.frame = CGRectMake(SCREEN_WIDTH_XT / 2 - self.fly_w / 2, SCREEN_HEIGHT_XT + self.fly_h, self.fly_w, self.fly_h);
}
default:
break;
}
_flyView.backgroundColor = [UIColor purpleColor];
POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];
anim.toValue = [NSValue valueWithCGPoint:self.center];
// 速度
anim.springSpeed = 5;
// 弹力--晃动的幅度 (springSpeed速度)
anim.springBounciness = 10.0f;
[_flyView pop_addAnimation:anim forKey:@"animationShow"];
}
3. 移除视图
- (void)tapClickAction
{
POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];
anim.toValue = [NSValue valueWithCGPoint:CGPointMake(self.center.x, SCREEN_HEIGHT_XT + self.fly_h)];
[_flyView pop_addAnimation:anim forKey:@"animationRemove"];
anim.springSpeed = 5;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self removeFromSuperview];
});
}
—————————————
走心文章, 值得点赞 —文/夏天然后
时间: 2024-10-04 16:40:18