I donβt quite understand exactly what effect you are looking for, but you can do something like this by creating a new timestamp, putting it on the screen, animating moving it around the shortcut that you have on the screen, and then when it will be done, resets the old one and removes the timestamp. This might look like a non-auto audit:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UISwipeGestureRecognizer *left = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipe:)]; [left setDirection:UISwipeGestureRecognizerDirectionLeft]; [self.view addGestureRecognizer:left]; // if non-ARC, release it // [release left]; self.label1.text = @"Mo"; } - (void)leftSwipe:(UISwipeGestureRecognizer *)gesture { NSString *newText; UILabel *existingLabel = self.label1; // in my example, I'm just going to toggle the value between Mo and Curly if ([existingLabel.text isEqualToString:@"Curly"]) newText = @"Mo"; else newText = @"Curly"; // create new label UILabel *tempLabel = [[UILabel alloc] initWithFrame:existingLabel.frame]; [existingLabel.superview addSubview:tempLabel]; tempLabel.text = newText; // move the new label off-frame to the right tempLabel.transform = CGAffineTransformMakeTranslation(tempLabel.superview.bounds.size.width, 0); // animate the sliding of them into place [UIView animateWithDuration:0.5 animations:^{ tempLabel.transform = CGAffineTransformIdentity; existingLabel.transform = CGAffineTransformMakeTranslation(-existingLabel.superview.bounds.size.width, 0); } completion:^(BOOL finished) { existingLabel.text = newText; existingLabel.transform = CGAffineTransformIdentity; [tempLabel removeFromSuperview]; }]; // if non-ARC, release it // [release tempLabel]; }
This animation animates the label in relation to its supervisor. You can verify that the superview
parameter superview
set to "clip subviews". Thus, the animation will be limited to the borders of this superview
, which will give a slightly more polished look.
Note that when using automatic layout, the idea is the same (although the execution is more complicated). Basically configure your restrictions so that the new view is on the right, then in the animation block, update / replace the restrictions so that the original label is on the left, and the new one in the place of the original label and, finally, in the completion block reset the restrictions of the original label and delete the time stamp.
By the way, this is all infinitely simpler if you are comfortable with one of the built-in transitions:
- (void)leftSwipe:(UISwipeGestureRecognizer *)gesture { NSString *newText; UILabel *existingLabel = self.label1;
source share