gpt4 book ai didi

objective-c - 为 UIView 设置动画并将圆角半径保持为圆形

转载 作者:太空狗 更新时间:2023-10-30 03:48:15 24 4
gpt4 key购买 nike

我有一个圆圈 UIView :

  con=[[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width-size-delta, y , size, size)];
con.layer.borderColor=[UIColor whiteColor].CGColor;
con.layer.borderWidth=1.0;
con.backgroundColor=[UIColor clearColor];
con.layer.cornerRadius=con.frame.size.width/2.0;
con.clipsToBounds=YES;
[self addSubview:con];

稍后我想将它的大小更改为更大的,但是当我这样做时,在动画开始时您会看到一些矩形,然后它又变回圆形。

我想要一个平面动画,当它的帧发生变化时它会保持为一个圆圈。

   CGRect frm=startConfrm; //original frame of the circle

frm.size.width*=2;
frm.size.height*=2;
frm.origin.y=self.frame.size.height/2.0-frm.size.height/2.0;

[UIView animateWithDuration:1.5
delay:0.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{
con.frame=frm;
con.layer.cornerRadius=con.frame.size.width/2.0;
}
completion:^(BOOL finished){ }];

最佳答案

如果您只想缩放 View 大小,则可以使用以下代码。

[UIView animateWithDuration:2.0 animations:^{

con.transform = CGAffineTransformMakeScale(2, 2); // it will scale as double size

}completion:^(BOOL finished) {
// do whatever at animation completion
}
}];

要将 View 重置为正常大小,

con.transform = CGAffineTransformIdentity;

引用:https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGAffineTransform/index.html#//apple_ref/c/func/CGAffineTransformMakeScale

关于objective-c - 为 UIView 设置动画并将圆角半径保持为圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31428687/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com