CAAnimations only update your button's presentation layer, not it's real position. I'm not aware of any way to ask them continue to during the navigation controller's pop transition.
Instead, I'd use an NSTimer
or CADisplayLink
to animate the actual button position. A simplistic example:
// in MyViewController.m
static CGFloat kButtonSpeed = 0.2f;
static CGFloat kButtonMinY = 15.f;
static CGFloat kButtonMaxY = 160.f;
- (void)initiateButtonAnimation
{
if (_displayLink) {
return;
}
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(moveButton)];
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
}
- (void)moveButton
{
if (_frameTimestamp == 0) {
_frameTimestamp = [_displayLink timestamp];
return;
}
if (!_renderFrame) {
_renderFrame = !_renderFrame;
return;
}
double currentTime = [_displayLink timestamp];
double renderTime = currentTime - _frameTimestamp;
_frameTimestamp = currentTime;
CGFloat amount = renderTime * 60.f * kButtonSpeed;
CGFloat y = self.myButton.center.y;
if (!_moveButtonDown && y > kButtonMinY) {
y = y - amount;
}
else if (_moveButtonDown && y < kButtonMaxY)
y = y + amount;
else
_moveButtonDown = !_moveButtonDown;
self.myButton.center = CGPointMake(self.myButton.center.x, y);
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
// don't forget to invalidate & release
[_displayLink invalidate];
_displayLink = nil;
}