我在名爲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度旋轉) –