我在名为extendButton的节标题上有UIButton。按下时我想旋转180度。旋转UIButton表部分
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 3) {
OrderHistoryHeaderView *orderHeaderView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"OrderHistoryHeaderView"];
if (orderHeaderView == nil) {
orderHeaderView = [[[NSBundle mainBundle] loadNibNamed:@"OrderHistoryHeaderView" owner:self options:nil] objectAtIndex:0];
orderHeaderView.contentView.backgroundColor = [UIColor whiteColor];
[orderHeaderView.extendButton addTarget:self action:@selector(extendButtonPressed) forControlEvents:UIControlEventTouchUpInside];
}
return orderHeaderView;
}
ProductDetailHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"ProductDetailHeaderView"];
if (headerView == nil) {
headerView = [[[NSBundle mainBundle] loadNibNamed:@"ProductDetailHeaderView" owner:self options:nil] objectAtIndex:0];
headerView.contentView.backgroundColor = [UIColor whiteColor];
}
headerView.mainLabel.text = headerTitleArray[section];
return headerView;
}
- (void)extendButtonPressed {
if (isExtend) {
//call rotate method
[self rotateButton:sender];
//insert row
unsigned long rowCount = orderHistoryArray.count;
//show msg if no history data
if (rowCount == 0) {
[ShareFunction showSimpleAlertWithString:@"No order history data!!" inVC:self];
}
orderHistoryArray = nil;
NSMutableArray *indexPathSet = [[NSMutableArray alloc] init];
for (int i = 0 ; i < rowCount; i++) {
[indexPathSet addObject:[NSIndexPath indexPathForRow:i inSection:3]];
}
[_mainTableView beginUpdates];
[_mainTableView deleteRowsAtIndexPaths:indexPathSet withRowAnimation:UITableViewRowAnimationAutomatic];
[_mainTableView endUpdates];
} else {
//delete row
//call rotate method
[self rotateButton:sender];
orderHistoryArray = productHistoryArray;
//show msg if no history data
//if (orderHistoryArray.count == 0) {
// [ShareFunction showSimpleAlertWithString:@"No order history data!!" inVC:self];
//}
NSMutableArray *indexPathSet = [[NSMutableArray alloc] init];
for (int i = 0 ; i < orderHistoryArray.count; i++) {
[indexPathSet addObject:[NSIndexPath indexPathForRow:i inSection:3]];
}
[_mainTableView beginUpdates];
[_mainTableView insertRowsAtIndexPaths:indexPathSet withRowAnimation:UITableViewRowAnimationAutomatic];
[_mainTableView endUpdates];
}
}
而且我rotateButton方法
- (void)rotateButton:(UIButton*)button {
button.transform = CGAffineTransformMakeRotation(M_PI);
}
当我点击按钮,现在可以旋转180度的tableView该节展开,但是当我再次点击该按钮保持不变,没有旋转。我在这里错过了什么?
要动画一个180度旋转? –
@DuncanC是的先生 – SanitLee
看看你是否可以自己解决这个问题。看看'UIView'方法'animateWithDuration:动画:'。你想为按钮的transform属性设置动画效果。也看看函数'CGAffineTransformRotate()'。该函数进行转换并对其应用旋转。 (提示,M_PI是一个180度旋转) –