【发布时间】:2022-01-14 00:34:48
【问题描述】:
将图像设置为UIButton 称为bigIcon 后,我将其放入animateWithDuration 并更改其框架,然后运行代码,按钮大小立即更改(没有动画),但它从起点缓慢移动到终点(有动画),我该如何解决这个问题?我发现如果我确实为按钮设置了图像,这个问题就会消失。
代码如下:
- (void)bigImage:(MCGodCell *)godCell withImage:(UIImage *)image {
self.bigIcon = [UIButton new];
self.bigIcon.adjustsImageWhenHighlighted = NO;
[self.bigIcon setBackgroundImage:image forState:UIControlStateNormal];
CGFloat iconX = self.tableView.frame.size.width / 2.0;
CGFloat iconY = self.tableView.frame.size.height / 2.0;
self.bigIcon.frame = CGRectMake(iconX, iconY, 1, 1);
[self.tableView addSubview:self.bigIcon];
CGFloat iconW = self.tableView.frame.size.width;
CGFloat iconH = iconW;
iconY = (self.view.frame.size.height - iconH) / 2.0;
[UIView animateWithDuration:0.3 animations:^{
self.bigIcon.frame = CGRectMake(0, iconY, iconW, iconH);
}];
}
【问题讨论】:
标签: ios objective-c