44313

UIImage is not transitioning using fade with animation block transition

Question:

I am doing an image transition using an animation block like this

[UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ self.songTitleLabel.text = currentSong.songTitle; self.artistNameLabel.text = currentSong.songArtist; self.songImageView.image = currentSong.songArtwork; }completion:^(BOOL finished){ self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:currentSong.songLocation error:nil]; [self.player setVolume:1.0]; [self.player play]; }];

I don't understand why I don't have a fade transition, I have tried several different UIAnimationOptionTransition... and every time I just get an abrupt jump to the next image (this happens to the text as well)

Can someone help me out?

Answer1:

You can't animate the changing of an image or text that way. I've done it like this,

-(IBAction)doStuff:(id)sender { [UIView transitionWithView:self.imageView duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ [self.imageView setImage:[UIImage imageNamed:@"IMG_0081.JPG"]]; } completion:nil]; [UIView transitionWithView:self.label2 duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ [self.label2 setText:@"New Text"]; } completion:nil]; }

If you're changing multiple labels or image views, it might be better to create a subclass, and override setText: and setImage:. For example, like this for setImage:,

-(void)setImage:(UIImage *)image { [UIView transitionWithView:self duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ [super setImage:image]; } completion:nil]; }

You can then just use,

self.imageView.image = ...

for any image view that's your subclass, and it will cross fade the images when you change them.

Recommend

  • How to play NSData from Core Data in AVAudioPlayer
  • Playing music in background ios app
  • AVAudioPlayer eliminating one second pause between sound files
  • Handling interruptions in Sprite Kit - can't get sound effects via [SKAction playSoundFileNamed
  • Tab bar with slide out menu
  • How to set view of programatically created view controller to SKView?
  • How to efficiently create lag variable using Stata
  • How can I pick a contact phone number in iOS?
  • Chaining multiple async functions in Swift
  • UIView transitionFromView: how can I do black background during transition?
  • How to check if user is logged in with FBSDKLoginKit in iOS?
  • MagicalRecord completion block is not called under test target
  • Akka pattern for handling asynchronous actions in receive
  • How Fade in UIButton
  • xcode issues when coming from another view controller
  • Eclipse, completion of inner classes
  • Wiring top-level DAGs together
  • How to implement AVAudioPlayer Inside Singleton Method?
  • How to get a item's coordinates while it is animating?
  • Where and How To Define An Application Property? - JHIpster
  • How to Navigate from Initial UIViewController to UISplitViewController in Swift
  • Eclipse code fomatting
  • Thread Synchronization with IntentService
  • Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2
  • Can someone please explain how this implementation of bucket sort works?
  • Where to put clearQueue in jQuery code
  • Spring Integration debounce/deduplicate
  • Generate a unique string based on a pair of strings
  • “A GKScore must specify a leaderboard.”
  • Wait for .each() .getJSON request to finish before executing a callback
  • Deleting a widget from QTableView
  • Is there any way to call saveCurrentTurnWithMatchData without sending a push notification?
  • multidatatrigger with multibinding in ControlTemplate.Triggers
  • Is there a parser equivalent of 'fragment' marking in ANTLR4?
  • HTML5 video only works in IE. The other browsers shows the black screen
  • Do query loads all the data in memory
  • Build Successful but not running on simulator
  • MySQL WHERE-condition in procedure ignored
  • Adding custom controls to a full screen movie
  • playing video using jmf