How to create Label text slider - ios

I have created slider in my app. How to add loop in my code. Because my label text slide only one time but i want to label text repeat (loop) on label. How it possible?
My Label slider code
Make globalCounter as global variable
globalCounter=0;
if(nameArray.count>0){
[self changeLable];
}
Then
-(void)changeLable{
if(!(globalCounter<nameArray.count)){
return;
}
NSLog(#"globalCounter %d",globalCounter);
[UIView animateWithDuration:1
delay:0.5
options: UIViewAnimationOptionTransitionCrossDissolve
animations:^{
}
completion:^(BOOL finished) {
[lblTitle setText:[nameArray objectAtIndex:globalCounter]];
globalCounter++;
[self performSelector:#selector(changeLable) withObject:nil afterDelay:1];
}];
}
Edit
-(void)changeLable{
if(!(globalCounter<nameArray.count)){
globalCounter=0;
}
NSLog(#"globalCounter %d",globalCounter);
[UIView animateWithDuration:1
delay:0.5
options: UIViewAnimationOptionTransitionCrossDissolve
animations:^{
}
completion:^(BOOL finished) {
[lblTitle setText:[nameArray objectAtIndex:globalCounter]];
globalCounter++;
[self performSelector:#selector(changeLable) withObject:nil afterDelay:1];
}];
}

do like
globalCounter=0;
if(des.count>0){
[_label setText:[des objectAtIndex:globalCounter]];
[self changeLable];
}
and call method like
-(void)changeLable{
if(globalCounter < des.count){
[UIView animateWithDuration:0.
delay:0.5
options: UIViewAnimationOptionTransitionCrossDissolve
animations:^{
}
completion:^(BOOL finished) {
if(globalCounter>=des.count){
globalCounter=0;//set counter to zero after it exceeds array count to repeat text change round repeated
}else
{
[_label setText:[des objectAtIndex:globalCounter]];
globalCounter++;
[self performSelector:#selector(changeLable) withObject:nil afterDelay:1];
}
}];
}
}

Try below code, it may help:
-(void)changeLable{
NSLog(#"globalCounter %d",globalCounter);
[UIView animateWithDuration:1
delay:0.5
options: UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[lblTitle setText:[nameArray objectAtIndex:globalCounter]];
}
completion:^(BOOL finished) {
if(globalCounter>nameArray.count)){
globalCounter=0;//set counter to zero after it exceeds array count to repeat text change round repeated
}else{
globalCounter++;
}
[self performSelector:#selector(changeLable) withObject:nil afterDelay:1];
}];
}

This is my answer brother.Sorry I could not answer immediately as I had some work.I downloaded and ran your project.First it crashes as you handled the wrong array count.So it bounds the array.After that I set the condition inside the black.
-(void)changeLable
{
NSLog(#"globalCounter %d",globalCounter);
[UIView animateWithDuration:1
delay:0.5
options: UIViewAnimationOptionTransitionCrossDissolve
animations:^{
}
completion:^(BOOL finished)
{
if(globalCounter<des.count)
{
_label.text = #"";
[_label setText:[des objectAtIndex:globalCounter]];
globalCounter++;
}
else
globalCounter=0;
[self performSelector:#selector(changeLable) withObject:nil afterDelay:1];
}];
}

Related

Update slider value on label when slider animates

I am using slider in my app. I have done all the setup only problem i am facing is the label on which i want slider values is not updating. Have a look at my code.
I have a button which on click animates the slider. I am not able to update my label as it shows 0.0 throughout the animation.
Any help will be highly appreciated.
- (IBAction)btnClicked:(id)sender
{
[UIView animateWithDuration:10 animations:^{
[self.slider setValue:0.0 animated:true];
} completion:^(BOOL finished) {
[UIView animateWithDuration:10 animations:^{
[self.slider setValue:100.0 animated:true];
}];
}];
}
Your code is not working because you try to set the maximum value to the slider so that it is simply set that maximum value with animation nothing more. Try my code that may be help you.
Change your btnClicked with this
- (IBAction)btnClicked:(id)sender {
[self.slider setValue:0 animated:true];
[self setSliderValue:1];
}
Add this setSliderValue method
- (void)setSliderValue:(float)value {
[UIView animateWithDuration:0.2 animations:^{
[self.slider setValue:value animated:true];
} completion:^(BOOL finished) {
self.lblSliderValue.text = [NSString stringWithFormat:#"%0.0f", self.slider.value];
if (self.slider.value != self.slider.maximumValue) {
[self setSliderValue:value+1];
}
}];
}
Hope this will help you.
Try like this:
- (IBAction)btnClicked:(id)sender
{
[self.slider setValue:0.0 animated:true];
[UIView animateWithDuration:10 animations:^{
[slider addTarget:self action:#selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
} completion:^(BOOL finished) {
[UIView animateWithDuration:10 animations:^{
//[self.slider setValue:100.0 animated:true];
}];
}];
}
sliderChanged method is like this:
- (void)sliderChanged:(UISlider *)slider {
self.label.text = [NSString stringWithFormat:#"%0.2f", slider.value];
}

Dismiss a view with animation

I am popping the couponDetailsView with bounce animation. But i want to dismiss the view from left to right animation. How can i do this? Below is my source code. Any kind of help would be really helpful.
#pragma mark Bounce Animation
-(void) openContentDetailsView
{
[self.view bringSubviewToFront:self.couponDetailsView];
[UIView animateWithDuration:0.2 animations:
^(void){
self.couponDetailsView.transform = CGAffineTransformScale(CGAffineTransformIdentity,1.1f, 1.1f);
self.couponDetailsView.alpha = 0.5;
}
completion:^(BOOL finished){
[self bounceOutAnimationStoped];
}];
}
- (void)bounceOutAnimationStoped
{
[UIView animateWithDuration:0.1 animations:
^(void){
self.couponDetailsView.transform = CGAffineTransformScale(CGAffineTransformIdentity,0.9, 0.9);
self.couponDetailsView.alpha = 0.8;
}
completion:^(BOOL finished){
[self bounceInAnimationStoped];
}];
}
- (void)bounceInAnimationStoped
{
[UIView animateWithDuration:0.1 animations:
^(void){
self.couponDetailsView.transform = CGAffineTransformScale(CGAffineTransformIdentity,1, 1);
self.couponDetailsView.alpha = 1.0;
}
completion:^(BOOL finished){
[self animationStoped];
}];
}
- (void)animationStoped
{
}
- (IBAction)contentDetailsCloseButtonAction:(id)sender {
self.couponDetailsView.alpha = 0;
self.couponDetailsView.transform = CGAffineTransformScale(CGAffineTransformIdentity,0.6, 0.6);
}
Try this:
[UIView animateWithDuration:0.3f
delay:0.0f
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
[testView setFrame:CGRectMake(x, y, width, height)];
} completion:^(BOOL finished) {
[testView removeFromSuperview];
}];

ios show Button with animation show one by one here i add link

I have six button on view with two pair of two grid.The problem is how to show button with animation, here I attach example url how to create this type of animation.
In this example when you click on menu button then show button in side menu view with animation
https://github.com/djardon/SideMenuFrostedAnimated
I tried this but I can't get any success.
I have two button one is btnHome and second is btnAbout:
-(void)animationStart
{
[btnHome setAlpha:0.f];
[UIView animateWithDuration:1.f delay:0.f options:UIViewAnimationOptionCurveEaseIn animations:^{
[btnHome setAlpha:0.f];
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.f delay:0.f options:UIViewAnimationOptionCurveEaseInOut animations:^{
[btnHome setAlpha:1.f];
[self animationStart2];
} completion:nil];
}];
}
-(void)animationStart2
{
[btnAbout setAlpha:0.0f];
//fade in
[UIView animateWithDuration:2.0f animations:^{
[btnAbout setAlpha:1.0f];
} completion:^(BOOL finished) {
//fade out
[UIView animateWithDuration:2.0f animations:^{
[btnAbout setAlpha:0.0f];
} completion:nil];
}];
}
Try this.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
btnHome.alpha=0.0;
btnAbout.alpha=0.0;
}
-(void)animationStart
{
[UIView animateWithDuration:0.4f delay:0.0f options: UIViewAnimationOptionCurveEaseInOut animations:^{
btnHome.alpha=1.0;
} completion:^(BOOL finished) {
[self animationStart2];
}];
}
-(void)animationStart2
{
[UIView animateWithDuration:0.4f delay:0.0f options: UIViewAnimationOptionCurveEaseInOut animations:^{
btnAbout.alpha=1.0;
} completion:^(BOOL finished) {
}];
}
- (IBAction)btnClick:(id)sender
{
[self animationStart];
}
Here initially i am setting the buttons alpha value to 0.0f. On click of third button i am showing these two buttons.

performSelector is calling new in if loop

i have
if (_moves <=19) {
[self performSelector:#selector(changeLabelState:) withObject:nil afterDelay: 1.0];
}
And the Method:
- (void)changeLabelState:(NSTimer *)timer
{
[UIView transitionWithView:self.movesLeftLabel duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.movesLeftLabel.textColor = [UIColor whiteColor];
} completion:^(BOOL finished) {
[UIView transitionWithView:self.movesLeftLabel duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.movesLeftLabel.textColor = [UIColor darkGrayColor];
} completion:^(BOOL finished) {
}];
}];
[self performSelector:#selector(changeLabelState:) withObject:nil afterDelay:1.5];
}
So if _moves = 19, everything works fine. its changing to white and back to grey. but if the _moves = 18, it calls another time, and the transition is too fast.
how can i do it that he is not calling it another time?
If you wrote you code in loop, and you do not want to perform selector more than one time try to add 'break;' after perform
if (_moves <=19) {
[self performSelector:#selector(changeLabelState:) withObject:nil afterDelay: 1.0];
break;
}
or, if you want, change clause to
if (_moves ==19) {
[self performSelector:#selector(changeLabelState:) withObject:nil afterDelay: 1.0];
}

Transition view on the same ViewContoller

I am trying to flip transition on the same ViewController, I have a button for trigger transition. I want to change theme color when i press to button via flip transition.
i used this code part:
- (IBAction)changeThemeButtonTapped:(id)sender
{
int tempThemeColor = [[NSUserDefaults standardUserDefaults]integerForKey:#"themeColor"];
if (tempThemeColor == 10) {
[self loadTheme];
[UIView transitionFromView:self.view
toView:self.view
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished) {
NSLog(#"finished");
}];
}else{
[self loadTheme];
[UIView transitionFromView:self.view
toView:self.view
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished) {
NSLog(#"finished");
}];
}
}
when i press to button, view turns to black. Is there any way to do? What is my mistake?
Thank you for your answer and interest.
I found my question's answer.
if (tempThemeColor == 10) {
[self loadTheme];
[UIView transitionWithView:self.view
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
} completion:^(BOOL finished) {
}];
}else{
[self loadTheme];
[UIView transitionWithView:self.view
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
} completion:^(BOOL finished) {
}];
}
Before doing animation try to change the window/super view of the view's color
if (self.view.superview) {
self.view.superview.backgroundColor = [UIColor whiteColor];
}
self.view.window.backgroundColor = [UIColor whiteColor];

Resources