@property (nonatomic, strong)UIDynamicAnimator *animator;
@property (nonatomic, strong)UIVisualEffectView *effectView;
// 展示Siri 效果
[self showEffectView];
-(UIDynamicAnimator *)animator
{
if (_animator==nil) {
//创建物理仿真器(ReferenceView:参照视图,设置仿真范围)
self.animator=[[UIDynamicAnimator alloc]initWithReferenceView:self.view];
}
return _animator;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self testGravity];
}
-(void)testGravity
{
//重力行为
UILabel *label = [[UILabel alloc] init];
label.text = @"What can I do for you?";
label.font = [UIFont systemFontOfSize:28];
[label sizeToFit];
label.center = self.view.center;
label.transform = CGAffineTransformMakeRotation(M_PI_4 * random());
self.redView = label;
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor colorWithRed:(arc4random()%100 + 100)/255.f green:(arc4random()%100 + 100)/255.f blue:(arc4random()%100 + 100)/255.f alpha:1.00f];
[self.effectView.contentView addSubview:label];
UIGravityBehavior *gravity=[[UIGravityBehavior alloc]init];
[gravity addItem:self.redView];
[self.animator addBehavior:gravity];
UICollisionBehavior *collision = [[UICollisionBehavior alloc]init];
collision.translatesReferenceBoundsIntoBoundary = YES;
[collision addItem:self.redView];
[self.animator addBehavior:collision];
}
- (void)showEffectView {
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:nil];
effectView.frame = self.view.bounds;
[self.view addSubview:effectView];
self.effectView = effectView;
UILabel *label = [[UILabel alloc] init];
label.text = @"What can I do for you?";
label.font = [UIFont systemFontOfSize:28];
[label sizeToFit];
[effectView.contentView addSubview:label];
label.center = self.view.center;
[UIView animateWithDuration:1.5 delay:0 usingSpringWithDamping:1.0 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
effectView.effect = blurEffect;
label.center = CGPointMake(self.view.center.x, self.view.center.y - 100);
} completion:^(BOOL finished) {
}];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureClicked:)];
[effectView addGestureRecognizer:tapGesture];
}
- (void)tapGestureClicked:(UITapGestureRecognizer *)tap {
UIVisualEffectView *effectView = (UIVisualEffectView *)tap.view;
[UIView animateWithDuration:1.5 delay:0 usingSpringWithDamping:1.0 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
//effectView.effect = nil;
[effectView viewWithTag:110].center = CGPointMake(self.view.center.x, 0);
} completion:^(BOOL finished) {
}];
}
Siri 效果实现外加UIDynamic有趣动画
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 先说下基本动画部分基本动画部分比较简单, 但能实现的动画效果也很局限使用方法大致为: 创建原始UI或者画面 创建C...
- 之前的文章都写上csdn上,主要觉得简书是分享文字的地方,最近发现关注我的开发专题人挺多的,就打算把这篇技术文章也...
- 文章源自:http://www.uisdc.com/css3-hover-effects-tutorials 这里...