UIScrollView始终动画!

时间:2010-09-05 16:05:58

标签: iphone animation uiscrollview

我对UIScrollView有一点问题。基本上,我正在使用PageControl示例应用程序中的代码进行一些修改。我正在将滚动视图添加到我的导航堆栈中,我希望它在到达那里时位于特定页面上。我正在尝试使用UIScrollView scrollToRect:animated:方法,但即使我传入NO,它仍然是动画!这是一段代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = indexPath.row;
viewController.currentPage = row;

CGRect frame = viewController.scrollView.frame;
frame.origin.x = frame.size.width * row;
frame.origin.y = 0;
[viewController.scrollView scrollRectToVisible:frame animated:NO];

[self.navigationController pushViewController:viewController animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

有谁知道为什么?

谢谢!

2 个答案:

答案 0 :(得分:3)

尝试使用setContentOffset:animated:

int xOffset = viewController.scrollView.frame.size.width * row;
[viewController.scrollView setContentOffset:CGPointMake(xOffset, 0) animated:NO];

答案 1 :(得分:1)

我最终使用CoreAnimation来制作自定义动画,效果非常好:

- (void) altAnimatePopViewControllerAnimated:(BOOL)animated
{
[CATransaction begin];

CATransition *transition;
transition = [CATransition animation];
transition.type = kCATransitionPush;          // Use any animation type and subtype you like
transition.subtype = kCATransitionFromRight;
transition.duration = 0.3;

CATransition *fadeTrans = [CATransition animation];
fadeTrans.type = kCATransitionFade;
fadeTrans.duration = 0.3;


[CATransaction setValue:(id)kCFBooleanTrue
                 forKey:kCATransactionDisableActions];

[[[[self.view subviews] objectAtIndex:0] layer] addAnimation:transition forKey:nil];
[[[[self.view subviews] objectAtIndex:1] layer] addAnimation:fadeTrans forKey:nil];



[self  popViewControllerAnimated:YES];
[CATransaction commit];
 }

- (void) altAnimatePushViewController:(UIViewController *)viewController Animated:(BOOL)animated
{
[CATransaction begin];

CATransition *transition;
transition = [CATransition animation];
transition.type = kCATransitionPush;          // Use any animation type and subtype you like
transition.subtype = kCATransitionFromRight;
transition.duration = 0.3;

CATransition *fadeTrans = [CATransition animation];
fadeTrans.type = kCATransitionFade;
fadeTrans.duration = 0.3;


[CATransaction setValue:(id)kCFBooleanTrue
                 forKey:kCATransactionDisableActions];

[[[[self.view subviews] objectAtIndex:0] layer] addAnimation:transition forKey:nil];
[[[[self.view subviews] objectAtIndex:1] layer] addAnimation:fadeTrans forKey:nil];



[self  pushViewController:viewController animated:YES];
[CATransaction commit];
}