Note that there are some explanatory texts on larger screens.

plurals
  1. POAnimating UIView origin only works after first try
    primarykey
    data
    text
    <p>I have a UIView with some labels in it I built in my storyboard that I want to animate when a map annotation is clicked. I have everything working great except the animations are a bit off. The first time you click an annotation the frame position is not animated. But if I deselect and then reselect the annotation it animates fine from then on. I also animate the background color and that seems to be working fine on the first select so whatever it is is peculiar to the frame property, perhaps because it's no set up appropriately at load? Again I did all that in the storyboard so I don't know what I'm missing.</p> <p>Code for my Labels/View (all built in my storyboard and using reference outlets to the proper IBOutlets). file.h:</p> <pre><code>@property (weak, nonatomic) IBOutlet UIView *stationinfo; @property (weak, nonatomic) IBOutlet UILabel *stationname; @property (weak, nonatomic) IBOutlet UILabel *stationsong; @property (weak, nonatomic) IBOutlet UILabel *stationartist; </code></pre> <p>file.m:</p> <pre><code>@synthesize stationinfo; @synthesize stationname; @synthesize stationsong; @synthesize stationartist; </code></pre> <p>Please find code for callbacks below:</p> <pre><code>- (void) mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view { //NSLog(@"Selected "); self.stationname.text = ((userStation *)view.annotation).name; self.stationsong.text = ((userStation *)view.annotation).song; self.stationartist.text = ((userStation *)view.annotation).artist; [UIView animateWithDuration:0.25 delay: 0.0 options: UIViewAnimationCurveEaseInOut animations:^ { CGRect anim = self.stationinfo.frame; anim.origin.y = 0.0; self.stationinfo.frame = anim; self.stationinfo.backgroundColor = [UIColor redColor]; } completion:^(BOOL finished){ NSLog(@"DONE!"); }]; } - (void) mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view { //NSLog(@"Deselected"); [UIView animateWithDuration:0.25 delay: 0.0 options: UIViewAnimationCurveEaseInOut animations:^ { CGRect anim = self.stationinfo.frame; anim.origin.y = -100.0; self.stationinfo.frame = anim; self.stationinfo.backgroundColor = [UIColor greenColor]; } completion:^(BOOL finished){ NSLog(@"DONE!"); }]; } </code></pre> <p>Your help is much appreciated. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload