Differences between [UIView transitionWithView ...] and [UIView transitionFromView ...]

Currently, I have a view that is contained in the view. The main view controller (parent view) has a property that is connected to the subzone in the interface builder. There is a button in the preview. I want the button to switch the subview, keeping the main view still. Currently, I have the following code in my IBAction for a button:

[UIView transitionWithView: self.subViewFront duration: 1.0 options: UIViewAnimationOptionTransitionFlipFromTop animations: nil completion: nil]; [UIView commitAnimations]; [[self view] addSubview: self.subViewBack; 

This code works fine, however, I noticed the following when I looked at the Apple API link:

Using the methods in this section is not recommended in iOS 4 and later. Use block-based animation methods instead.

Following this tip, I tried using the following code:

 [UIView transitionFromView: self.subViewFront toView: self.subViewBack duration: 1.0 options: UIViewAnimationOptionTransitionFlipFromTop completion: nil]; 

It seems like it should do the same as what I originally encoded, however, when I run my application with this code, it flips my whole mind (parent and child), and not just the preview. Should this method be used as a replacement from the original method I used, or is there something I am missing? Thanks.

+4
source share
1 answer

I had the same problem (with parent animation instead), but resolved it by adding two views ( subViewFront and subViewBack ) instead of the container.

So, add your two views to the UIView container, and then use -transitionFromView:... just like in your example:

 UIView *container = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease]; [self.view addSubview:container]; ... [container addSubview:self.subViewFront]; [container addSubview:self.subViewBack]; 
+4
source

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


All Articles