Animation on view's frame reposition overlaps another view

138 Views Asked by At

I appreciate if somebody could help me on finding a solution to the next situation.

I want to animate the reposition of an UIView to one point to another one (I was able to do this, please check code below), but I have another UIView in the middle .. in fact this second view in positioned inmediately after the view i want to move. What i want to accomplish basically is to avoid seeing the animation over this second view.

    //second view placed at position x = 100, width = 20, height = 20
    UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(100, 0, 20, 20)];
    seconView.backgroundColor = [UIColor redColor];
    [self.superview addSubview:secondView];

    //from now on, this code occurs when tapping a button

   //main view placed at position x = 0, width = 100, height = 20
   UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 20)];
   view.backgroundColor = [UIColor yellowColor];

   [self.superview addSubview:view];

   [UIView beginAnimations:@"moveView" context:nil];
   [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
   [UIView setAnimationDuration:0.7f];
   //main view will be moved to position x = 120, meaning that it will go through the second view.
   subView.frame = CGRectOffset(view.frame, view.frame.size.width + seconView.frame.size.width, 0);

    [UIView commitAnimations];

I've been playing with the zposition, opaque, opacity, alpha and bringToFront properties with no succeed at all.

1

There are 1 best solutions below

0
On

I already figured it out.

My issue was that I had UIBUttons instead, so I placed them inside UIViews and set a bigger zposition to the second view and also the background color must be the one from the superview.