[英]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.