我想重新创建 Apple 在编辑模式下在其 UITableViews 中使用的旋转减号按钮。你可以在this video on YouTube中看到动画.
有没有办法将这个按钮(和动画)嵌入到我自己的其他地方的 View 中?或者我真的必须重新创建它吗?我需要每个州的图片吗?
此外,这是该视频中按钮中间动画的图片。
谢谢!
最佳答案
创建一个按钮并使用 layer
属性的阴影属性将不起作用,因为当图像旋转时,您不希望阴影也旋转。我通过执行以下操作重新创建了这种效果。我创建了两个 35px 正方形的图像。一次叫delete-icon-bg.png
,一次叫delete-icon-dash.png
。 delete-icon-bg.png
就是我想要的红色圆圈样式,而 delete-icon-dash.png
是一个透明的 png,白色破折号居中我想要它的背景。然后我像这样配置按钮:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"delete-icon-bg.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"delete-icon-dash.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(didTouchDeleteButton:) forControlEvents:UIControlEventTouchUpInside];
button.adjustsImageWhenHighlighted = NO;
button.contentMode = UIViewContentModeCenter;
didTouchDeleteButton:
方法看起来像这样:
- (void)didTouchDeleteButton:(UIButton *)sender
{
if (sender.selected) {
sender.selected = NO;
[UIView beginAnimations:@"undoRotateDash" context:nil];
[UIView setAnimationDuration:0.3];
sender.imageView.transform = CGAffineTransformMakeRotation(0.0);
[UIView commitAnimations];
} else {
sender.selected = YES;
[UIView beginAnimations:@"rotateDash" context:nil];
[UIView setAnimationDuration:0.3];
sender.imageView.transform = CGAffineTransformMakeRotation(-M_PI_2);
[UIView commitAnimations];
}
}
关于ios - 如何重新创建 Apple 在标准 iOS UITableView 中使用的旋转减号按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7989095/