Ios 设置UIView的动画以使其增长和收缩?
我有一个Ios 设置UIView的动画以使其增长和收缩?,ios,objective-c,swift,Ios,Objective C,Swift,我有一个ui视图 如何设置此视图的动画,使视图变大(宽度、高度),然后再次缩小到其原始大小?只需应用ui视图动画,然后应用动画的相反方向,即可恢复原始视图 UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)]; [UIView animateKeyframesWithDuration:1.0 delay:0.0
ui视图
如何设置此视图的动画,使视图变大(宽度、高度),然后再次缩小到其原始大小?只需应用
ui视图
动画,然后应用动画的相反方向,即可恢复原始视图
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)];
[UIView animateKeyframesWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction
animations:^{
myView.frame = CGRectMake(0,0,200,300);
} completion:^(BOOL finished){
}];
只需应用
ui视图
动画,然后应用动画的相反方向即可恢复原始视图
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)];
[UIView animateKeyframesWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction
animations:^{
myView.frame = CGRectMake(0,0,200,300);
} completion:^(BOOL finished){
}];
迅速回答
Swift 2
//Get Smaller
UIView.animateWithDuration(1.0, animations: {
self.view.frame.size.height -= 100
self.view.frame.size.width -= 100
})
//grow
UIView.animateWithDuration(1.0, animations: {
self.view.frame.size.height += 100
self.view.frame.size.width += 100
})
Swift 3,4,5
//Get Smaller
UIView.animate(withDuration: 1.0, animations: {
self.view.frame.size.height -= 100
self.view.frame.size.width -= 100
})
//grow
UIView.animate(withDuration: 1.0, animations: {
self.view.frame.size.height += 100
self.view.frame.size.width += 100
})
迅速回答
Swift 2
//Get Smaller
UIView.animateWithDuration(1.0, animations: {
self.view.frame.size.height -= 100
self.view.frame.size.width -= 100
})
//grow
UIView.animateWithDuration(1.0, animations: {
self.view.frame.size.height += 100
self.view.frame.size.width += 100
})
Swift 3,4,5
//Get Smaller
UIView.animate(withDuration: 1.0, animations: {
self.view.frame.size.height -= 100
self.view.frame.size.width -= 100
})
//grow
UIView.animate(withDuration: 1.0, animations: {
self.view.frame.size.height += 100
self.view.frame.size.width += 100
})
只需使用transform的scale属性执行
UIView动画
目标C:
[UIView animateWithDuration:1
animations:^{
yourView.transform = CGAffineTransformMakeScale(1.5, 1.5);
}
completion:^(BOOL finished) {
[UIView animateWithDuration:1
animations:^{
yourView.transform = CGAffineTransformIdentity;
}];
}];
Swift 3.0:
UIView.animate(withDuration: 1, animations: {
yourView.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
}) { (finished) in
UIView.animate(withDuration: 1, animations: {
yourView.transform = CGAffineTransform.identity
})
}
cAffineTransformMakeScale
缩放视图,并将视图还原为原始形式。只需使用transform的scale属性执行UIView动画
目标C:
[UIView animateWithDuration:1
animations:^{
yourView.transform = CGAffineTransformMakeScale(1.5, 1.5);
}
completion:^(BOOL finished) {
[UIView animateWithDuration:1
animations:^{
yourView.transform = CGAffineTransformIdentity;
}];
}];
Swift 3.0:
UIView.animate(withDuration: 1, animations: {
yourView.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
}) { (finished) in
UIView.animate(withDuration: 1, animations: {
yourView.transform = CGAffineTransform.identity
})
}
cAffineTransformMakeScale
缩放视图,并cAffineTransformIdentity
将视图还原回其原始形式。使用CAKeyframeAnimation设置增长和收缩动画的简单方法
let animation = CAKeyframeAnimation(keyPath: "transform.scale")
animation.values = [1.0, 1.2, 1.0]
animation.keyTimes = [0, 0.5, 1]
animation.duration = 1.5
animation.repeatCount = Float.infinity
view.layer.add(animation, forKey: nil)
使用CAKeyframeAnimation设置生长和收缩动画的简单方法
let animation = CAKeyframeAnimation(keyPath: "transform.scale")
animation.values = [1.0, 1.2, 1.0]
animation.keyTimes = [0, 0.5, 1]
animation.duration = 1.5
animation.repeatCount = Float.infinity
view.layer.add(animation, forKey: nil)
你要应用反转吗?只要你想,只要在代码的动画块中应用你想要的反转帧。你要应用反转吗?只要你想,只需在代码的动画块中应用所需的反向帧。如何组合两个动画使其首先大于收缩到其原始大小?如何组合两个动画使其首先大于收缩到其原始大小?效果非常好!最好的解决方案!很好!最好的解决方案!