Animation iPhone: how to animate only subview? Not the whole look?

I am new to animation and I am using the following code to animate Flip animations.

//MyMapView is UIView

MyMapView *aMapView = [[MyMapView alloc] initWithFrame:CGRectMake(0, 118, 321, 300) AndResArray:self.nearMeArray];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
    [[self view] addSubview:nearMeMap];

    [UIView commitAnimations];

Works great. But the whole view (with superview) is Flips.

I want Flip subview to be MyMapView. Superview should not be flipped.

How to do it???

EDITED

screen:

Below is the main screen. When I click on the "Map" button, I want to flip only the brown part of the screen. The entire screen should not be flipped.

enter image description here

Thank...

+5
source share
5 answers

I will find out what the problem is. See below code.

MapView.m

- (id)initWithFrame:(CGRect)frame {

self = [super initWithFrame:frame];
if (self) {
    // Initialization code.

    [self performSelector:@selector(addMapView) withObject:nil afterDelay:2.0];

}
return self;
}

- (void) addMapView {

//MyMapView is UIView

MKMapView  *aMapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 321, 300)];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self cache:YES];
[self addSubview:aMapView];

[UIView commitAnimations];

}

And after that, just add an object of the MapView class where you want. as shown below.

//MyMapView is UIView
mapView  *aMapView = [[mapView alloc] initWithFrame:CGRectMake(0, 118, 321, 300)];
[[self view] addSubview:aMapView];

, .

,

MinuMaster.

+3

Matteo , , . :

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
                       forView:aMapView
                         cache:YES];
[self.view addSubview:aMapView];
[UIView commitAnimations];

API, iOS 4. .

[UIView transitionWithView:aMapView
        duration:1.0
        options:UIViewAnimationTransitionFlipFromRight
        animations:^{ [self.view addSubview:aMapView]; }
        completion:^(BOOL f){ }
];
+2

self.view, aMapView:

MyMapView *aMapView = [[MyMapView alloc] initWithFrame:CGRectMake(0, 118, 321, 300) AndResArray:self.nearMeArray];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[self.view addSubView:aMapView];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:aMapView cache:YES];

[UIView commitAnimations];
+1

, , . , , . , .

The simplest solution is probably just to introduce an intermediate idea that the size and position of the card will go. Then leave this view when adding a map to it.

See the “Viewing the Programming Guide” section on Creating animated transitions between views for more information . Although the methods that you use in iOS 4 have been replaced with new block versions.

+1
source
-(void)viewDidLoad
{
    [super viewDidLoad];

    OptionView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 70)];
    OptionView.backgroundColor=[UIColor blueColor];
    OptionIsShow=false;

    MoveView=[[UIView alloc] initWithFrame:CGRectMake(40, 40, 70, 70)];
    [MoveView setBackgroundColor:[UIColor redColor]];
    [self.view addSubview:MoveView];

}

-(void)ViewOrHideOptionView
{

        CGContextRef context = UIGraphicsGetCurrentContext();
        [UIView beginAnimations:nil context:context];

        [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.MoveView cache:NO];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:1.0];

        if(!OptionIsShow)
        {
            [self.MoveView addSubview:OptionView];
            OptionIsShow=true;
        }
        else
        {
            [self.OptionView removeFromSuperview];
            OptionIsShow=false;
        }

        [UIView commitAnimations];
}
0
source

All Articles