How to move uiview from left to right and vice versa

Hi, I am developing one application. In that, I made an animation for one view to move left to right and right to left and change the values ​​for the labels contained in this view. But this view is deleted when I click left or the right button and the new view override the old view. Therefore, I do not want to redefine. Just want to add a new look. My code

-(void)centerAnimation1:(id)sender { UIView *currentView = daysview; theWindow = daysview; // set up an animation for the transition between the views CATransition *animation = [CATransition animation]; animation.delegate = self; [animation setDuration:0.4]; [animation setType:kCATransitionMoveIn]; if(rhtolft) { [animation setSubtype:kCATransitionFromLeft]; } else { [animation setSubtype:kCATransitionFromRight]; } [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"]; [currentView removeFromSuperview]; } - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{ if(animate) { CATransition *animation = [CATransition animation]; animation.delegate = self; [animation setDuration:0.4]; [animation setType:kCATransitionMoveIn]; if(rhtolft) { [animation setSubtype:kCATransitionFromLeft]; rhtolft=NO; } else { [animation setSubtype:kCATransitionFromRight]; } [[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"]; animate=NO; [self.view addSubview:daysview]; } } 

I just call the centerAnimation1 method in the right-click action method. After calling this, I changed the label values.

+4
source share
4 answers

try it

First click L to R

  CGRect basketTopFrame = Yourview.frame; basketTopFrame.origin.x = 115; [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{ Yourview.frame = basketTopFrame; } completion:^(BOOL finished){ }]; 

then R To L

  CGRect napkinBottomFrame = Yourview.frame; napkinBottomFrame.origin.x = 0; [UIView animateWithDuration:0.3 delay:0.0 options: UIViewAnimationOptionCurveEaseOut animations:^{ Yourview.frame = napkinBottomFrame; } completion:^(BOOL finished){/*done*/}]; 
+19
source

Use the code below,

 UIView * testView = [[UIView alloc] initWithFrame:CGRectMake(20.0f, 100.0f, 300.0f, 200.0f)]; [testView setBackgroundColor:[UIColor blueColor]]; [self.view addSubview:testView]; [UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{ [testView setFrame:CGRectMake(0.0f, 100.0f, 300.0f, 200.0f)]; } completion:nil]; [testView release]; 

And check out the link below: http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_uiview-animations/

+3
source

when the button presses UIView, it moves left and left.

Global Declare NSString * string = @ "one";

 - (void)viewDidLoad { [super viewDidLoad]; stringslider = @"one"; } Action Button "click" -(IBAction)slider:(id)sender{ if ([stringslider isEqualToString:@"one"]) { [UIView animateWithDuration:0.2 animations:^{[sliderview setFrame:CGRectMake(205, [sliderview frame].origin.y, 116, 275)]; } completion:nil]; stringslider = @"two"; } else if ([stringslider isEqualToString:@"two"]) { [UIView animateWithDuration:0.2 animations:^{[sliderview setFrame:CGRectMake(342, [sliderview frame].origin.y, 116, 275)]; } completion:nil]; stringslider = @"one"; } } easy uiview animation is done. 
+1
source

Try using the following code that I use in my applications:

 CGRect rectLeft = btnLeft.frame; rectLeft.origin.x = rectLeft.origin.x + rectLeft.size.width; CGRect rectRight = btnRight.frame; rectRight.origin.x = rectRight.origin.x - rectRight.size.width; [UIView animateWithDuration:0.5 animations:^{ btnLeft.frame = rectLeft; btnRight.frame = rectRight; } completion:nil]; 
0
source

Source: https://habr.com/ru/post/1478963/


All Articles