[英]iOS animation of single View left to right
我的動畫代碼現在可以正常工作:
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [cal components:( NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSTimeZoneCalendarUnit) fromDate:[[AXDateManager sharedInstance] currentDate]];
if (forward) {
[UIView transitionWithView:self.tableView
duration:ANIMATIONDURATION
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
/* maybe animation to hide your other views */
} completion:^(BOOL finished) {
/* remove the required views */
}];
[components setDay:components.day + 1];
} else {
[UIView transitionWithView:self.tableView
duration:ANIMATIONDURATION
options:UIViewAnimationOptionTransitionCurlDown
animations:^{
/* maybe animation to hide your other views */
} completion:^(BOOL finished) {
/* remove the required views */
}];
[components setDay:components.day - 1];
}
[self setupWithDate:[cal dateFromComponents:components]];
現在,我想從左到右切換到動畫。 但是我遇到了幾個問題。 我嘗試的一件事是復制原始tableview與
NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:self.tableView];
UITableView *tableView = [NSKeyedUnarchiver unarchiveObjectWithData:archivedData];
[tableView registerNib:[UINib nibWithNibName:@"Cell" bundle:nil] forCellReuseIdentifier:@"Cell"];
並將委托和數據源設置到新表,並從舊表中刪除委托和數據源。 但是以某種方式,新的設備永遠無法正確安裝,因此不會在其單元上顯示數據。 這是我嘗試使用的動畫:
[UIView animateWithDuration:3
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
CGRect oldTableRect = self.tableview.frame;
CGRect newTableRect = tableView.frame;
oldTableRect.origin.x = oldTableRect.origin.x - oldTableRect.size.width;
newTableRect.origin.x = newTableRect.origin.x - newTableRect.size.width;
self.tableView.frame = oldTableRect;
tableView.frame = newTableRect;
}
但是,使用上面的動畫,其中一個表從未動過。
我要實現的目標:
更多信息:
最好的方法是什么? 我可以只用一張桌子來實現從左到右的動畫,而與原來的動畫一樣,可以上下卷曲嗎?
編輯所以這就是我嘗試的。 兩件事不起作用。 舊表不會移到左側。 新表可以正確移動,但是無法設置數據。
if (forward) {
NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:self.tableView];
UITableView *tableView = [NSKeyedUnarchiver unarchiveObjectWithData:archivedData];
[tableView registerNib:[UINib nibWithNibName:@"Cell" bundle:nil] forCellReuseIdentifier:@"Cell"];
// for debugging
[self.tableView setBackgroundColor:[UIColor yellowColor]];
[tableView setBackgroundColor:[UIColor redColor]];
tableView.frame = self.tableView.frame;
CGRect rect = tableView.frame;
// -20 for debugging
rect.origin.x = rect.origin.x + rect.size.width - 20;
tableView.frame = rect;
[self.view addSubview:tableView];
tableView.dataSource = self;
tableView.delegate = self;
// keep reference to old tableview
UITableView *old = self.tableView;
self.tableView = tableView;
// setup new tableview with data
[components setDay:components.day + 1];
[self setupWithDate:[cal dateFromComponents:components]];
CGRect oldTableRect = old.frame;
CGRect newTableRect = tableView.frame;
oldTableRect.origin.x = oldTableRect.origin.x - oldTableRect.size.width;
newTableRect.origin.x = newTableRect.origin.x - newTableRect.size.width;
[UIView animateWithDuration:3
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
old.frame = oldTableRect;
self.tableView.frame = newTableRect;
}
completion:^(BOOL finished) {
[old removeFromSuperview];
}];
}
聲明並分配用於動畫的變量到動畫塊中對我來說聽起來有些奇怪,請嘗試以下操作:
CGRect oldTableRect = self.tableview.frame;
CGRect newTableRect = tableView.frame;
oldTableRect.origin.x = oldTableRect.origin.x - oldTableRect.size.width;
newTableRect.origin.x = newTableRect.origin.x - newTableRect.size.width;
[UIView animateWithDuration:3
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
self.tableView.frame = oldTableRect;
tableView.frame = newTableRect;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.