开发者

i have a problem in UIImageView's animating

-(IBAction) change {

   self.imageView.animationImages = myImages;
   self.imageView.animationDuration = 2;
   if(self.imageView.isAnimating == NO){
      [self.imageView startAnimating];
       NSLog(@"if bool = %d", self.imageView.isAnimating);
   }
   else {
       self.imageView stopAnimating];
       NSLog(@"else bool = %d", self.imageView.isAnimating);
   }
}

hello, i'm studying iOS programming.

but i have a question. i have a button and when i click the button, then this method will be called.

first i click the button, then this code will start the if statement. that's what i want.

i click the button again, i think that will execute the else statement.

开发者_StackOverflow

but it always execute the if statement only.

why is that? i really don't know why is that. please help me


I think setting the properties like animationImages or animationDuration will stop the animation, so that by clicking, you every time stop and then just after (re)start it in the if part. Try setting these two properties outside the action method you wrote, and just let the if/else sequence.

-(IBAction) change {
   // set these two anywhere else
   //self.imageView.animationImages = myImages;
   //self.imageView.animationDuration = 2;
   if(self.imageView.isAnimating == NO){
      [self.imageView startAnimating];
       NSLog(@"if bool = %d", self.imageView.isAnimating);
   }
   else {
       self.imageView stopAnimating];
       NSLog(@"else bool = %d", self.imageView.isAnimating);
   }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜