开发者

UIScrollView Always animating!

I have a little problem with UIScrollView. Basically, I'm using the code from the PageControl sample app with some modification. I'm adding the scroll view to my navigation stack, I want it to be on a开发者_C百科 specific page when it gets there. I am trying to use the UIScrollView scrollToRect: animated: method, but even though I pass in NO, it's still animating! Here's a code snippet:

- (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];
}

Does anyone know why?

Thanks!


Try using setContentOffset:animated::

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


I ended up using CoreAnimation to do a custom animation, which works very well:

- (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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜