I create a new tabbed application project in Xcode 4.2 using Storyboards. In viewDidLoad, I add the following code:
[UIView animateWithDuration:30
delay:0
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear
animations:^(void) {
CGRect imageViewFrame = self.scrollingImageView.frame;
imageViewFrame.origin.x = CGRectGetWidth(imageViewFrame) / -2;
self.scrollingImageView.frame = imageViewFrame;
} completion:nil];
Then I create the associated UIImageView property and wire it up in IB.
@property (nonatomic, strong) IBOutlet UIImageView *scrollingImageView;
I put an image into the imageview, run it in the simulator or my iPod Touch, and I see scrolling.
However, when I select the second tab and then go back to the first tab, the animation completes what appears to be immediately and I cannot get it to restart, even if I put the above into viewWillAppear. I have searched through lots of answers and cannot solve it.
Any help would be appreciated.
It appears that the issue you are dealing with is specific to tabbed bar controllers, not storyboards or the specific animation. The issue is that when you switch to a different tab, the animation stops, and when you return to the first tab, it doesn't resume.
Ordering the animation again in viewWillAppear
does not work (as you mentioned), but if you first remove the animation in viewWillDisappear
, then ordering it again in viewWillAppear
should work. For example
- (void)viewWillDisappear:(BOOL)animated
{
[self.view.layer removeAllAnimations]; // or whatever you need to use to remove your specific animation
}
NB: The animation removal code should be in viewWillDisappear
rather than in viewWillUnload
, since viewWillUnload
does not get called when you switch tabs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With