简体   繁体   中英

UIView does not move a subview when a animation block is after it

I have this UIView class. It has 4 Views in it:

  1. self.view The view of the class itself.
  2. Above that twitterButtonView that holds:
  3. A UIImageView of a button.
  4. Above that a hidden view of the back of the button.

The self.view has a frame of (30, 380, 68, 66);

I want to be able to tab the button and then it scales up accompanied by a UIViewAnimationTransitionFlipFromRigh t. Before the animation starts I set the frame of the class to be the whole screen. (I have to do this for the class to still respond to touches) Thats where my button moves to the top left. I'm doing a twitterButtonView.center = somePoint and nothing happens to the button view: (I removed unimportant parts)

        // I save the center of the class. Its where the the class is in the window.
    oldCenter = self.center;
    self.frame = CGRectMake(0, 0, 320, 480);
    // Set the button to the position where the class was.This is x=63 y=413 in the debugger
    // If I return; after this everything is fine and the class has the frame set to the whole
    // screen and the button is at 62,413
    twitterButtonView.center = oldCenter;
    [UIView beginAnimations:@"twitterButtonFlip" context:nil];
    [UIView setAnimationDuration:1.0];
    twitterButtonView.center = CGPointMake(160,220);
    [UIView commitAnimations];

The button moves to the center. But the animation starting point is 34,33. Why is that?

because the self.view center is 34, 33.

Instead try changing the origin of the frame (x or y).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM