2012-12-15 25 views
7

एनीमेट करें, उदाहरण के लिए मैं एक यूआईएसलाइडर को एनिमेट करना चाहता हूं 0.25 से 0.75 और पीछे। यह उपयोगकर्ता को दिखाना चाहिए कि क्या करना है।यूआईस्लाइडर को आसानी से

मैं इस कोशिश की:

[self incrementCounter:[NSNumber numberWithInt:0]]; 


-(void) incrementCounter:(NSNumber *)i { 
    [Slider setValue:[i floatValue]/1000]; 
    [self performSelector:@selector(incrementCounter:) withObject:[NSNumber numberWithInt:i.intValue+1] afterDelay:0.001]; 
} 

लेकिन इतना चिकनी नहीं thats ... मैं इस बात के लिए संक्रमण का उपयोग कर सकते हैं?

[Slider setValue:1 animated:YES]; 

उपवास रखने की ...

[UIView animateWithDuration:2.0 
       animations:^{ 
        [Slider setValue:0.2]; 
       }]; 
[UIView animateWithDuration:2.0 
       animations:^{ 
        [Slider setValue:0.5]; 
       }]; 

बस एक दूसरे एनिमेट होने ...

उत्तर

14

आप पहली बार के पूरा होने के ब्लॉक में दूसरी एनीमेशन रखकर श्रृंखला के लिए एनिमेशन की जरूरत है :

-(IBAction)animateSlider:(id)sender { 

    [UIView animateWithDuration:2 animations:^{ 
     [self.slider setValue:.75]; 
    } completion:^(BOOL finished) { 
     [UIView animateWithDuration:2 animations:^{ 
      [self.slider setValue:0.25];//or `[self.slider setValue:(.75)-(.5*finished)];` if you want to be safe 
     }]; 
    }]; 
} 
2

स्विफ्ट 2.2 संस्करण rdelmar के लिए के

@IBOutlet weak var slider: UISlider! 

func animateSlider(sender: AnyObject){ 
    UIView.animateWithDuration(2, animations: {() in 
     self.slider.setValue(0.75, animated: true) 
     }, completion:{(Bool) in 
      UIView.animateWithDuration(2, animations: {() in 
       self.slider.setValue(0.25, animated: true) 
      }) 
    }) 
} 

जवाब देने और कॉल करने के लिए समारोह पैरामीटर में UISlider पारित

animateSlider(self.slider) 

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^