How to add subview with flip animation?

If you create a completely new application with one view and put this code in a button:

UIView *blah = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)]; blah.backgroundColor = [UIColor grayColor]; [UIView transitionWithView:blah duration:1 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{ [self.view addSubview:blah]; } completion:^(BOOL finished){ }]; 

A subsection is added immediately without animation. If you add a subview first and then try to animate it ... you will get the same problem.

  UIView *blah = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)]; [self.view addSubview:blah]; [UIView transitionWithView:blah duration:1 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{ blah.backgroundColor = [UIColor grayColor]; } completion:^(BOOL finished){ }]; 

How on Earth do you activate a flip for spying or immediately after adding it?

+6
source share
2 answers

Usually you need to have a container that already limits the animation:

 - (void)viewDidLoad { [super viewDidLoad]; CGRect frame = CGRectMake(0, 0, 100, 100); _container = [[UIView alloc] initWithFrame:frame]; _container.backgroundColor = [UIColor lightGrayColor]; [self.view addSubview:_container]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; UIView *subview = [[UIView alloc] initWithFrame:_container.bounds]; subview.backgroundColor = [UIColor darkGrayColor]; [UIView transitionWithView:_container duration:1.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{ [_container addSubview:subview]; } completion:NULL]; } 
+12
source

It is worth a try:

 UIView *blah = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)]; blah.backgroundColor = [UIColor grayColor]; [self.view addSubview:blah]; blah.alpha = 0.0; //Or with blah.hidden = TRUE and then FALSE inside the animation block [UIView transitionWithView:blah duration:1 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{ blah.alpha = 1.0; } completion:^(BOOL finished){ }]; 
+1
source

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


All Articles