0

I have iPhone application.

I want that when view is loaded it has subView. Also I want that subView to be loaded like flipping or sliding from left to right in animation.

subView contains UIButton and TextView. I want that subView should load in animation like slide from left.

Nayan
  • 3,014
  • 2
  • 17
  • 33
user1567956
  • 131
  • 2
  • 6
  • 13

3 Answers3

1

Flipping a view can be done as follows:

    [UIView animateWithDuration:1 animation:^{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.subView cache:FALSE];
}];

Here is my complete code:

- (void) flipCard {

if (_isDisplayBackOfCard) {

    [UIView animateWithDuration:.5 animations:^{

        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:FALSE];
        [self.backOfCard removeFromSuperview];
        [self.view addSubview:self.frontOfCard];

    } completion:^(BOOL finished){
        _isDisplayBackOfCard = !_isDisplayBackOfCard;
    }];
}
else {

    [UIView animateWithDuration:.5 animations:^{

        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:FALSE];
        [self.frontOfCard removeFromSuperview];
        [self.view addSubview:self.backOfCard];

    } completion:^(BOOL finished){
        _isDisplayBackOfCard = !_isDisplayBackOfCard;
    }];
}

}

Sliding the view in can be easily achieved by setting the views frame inside an animation block:

CGRect _newFrame = CGRectMake(someValueForX, someValueForY, someValueForWidth, someValueForHeight);

    [UIView animateWithDuration:.5 animations:^{ [self.subView setFrame:_newFrame];}];
bennythemink
  • 5,096
  • 4
  • 36
  • 54
  • I'm guessing you may not be creating & setting the _newFrame variable? I've edited the code above to show you. Simply replace the x,y,width and height values with the ones you require and make sure you reference the correct sub view. – bennythemink Aug 07 '12 at 07:54
  • int someValue for X and y i need to give the values fo the x y of subview – user1567956 Aug 07 '12 at 08:03
0

You can do this by adding subView in viewDidLoad method of view and in the viewDidAppear method you can use the animation using block statement to give it some animation.

Happy Coding :)

EDIT 1

Here I have add scrollView in XIB attach the IBOutlate to it. You can programmatically add it to in the viewDidLoad method.

At the first I make the View hidden by applying this frame

subCatScroll.frame = CGRectMake(320, 0, 91, 436);

and on some button click I show it through animation (it is coming from right side edge of iPhone)

- (IBAction)done:(id)sender
{
    [Appirater userDidSignificantEvent:YES];
    if(pointer.hidden == YES)
    {
        [UIView beginAnimations:@"Move Me To Unhide" context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        [UIView setAnimationDuration:kAnimationDur];
        subCatScroll.frame = CGRectMake(229,0,91,436);
        [UIView setAnimationDelegate:self];
        [UIView commitAnimations];
        [self configureView];
        pointer.hidden = NO;
    }
    else
    {
        [UIView beginAnimations:@"Move Me To Hide" context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        [UIView setAnimationDuration:kAnimationDur];
        subCatScroll.frame = CGRectMake(320, 0, 91, 436);
        [UIView setAnimationDelegate:self];
        [UIView commitAnimations];        
        pointer.hidden = YES;
    }
}

Here the pointer is one control which is used to decide what to do with scrollView

The iOSDev
  • 5,237
  • 7
  • 41
  • 78
  • If you need some guidance about coding just ask about it :) – The iOSDev Aug 07 '12 at 07:20
  • yes i need some code guidance i just want to show and hide and subview with flip side on button click – user1567956 Aug 07 '12 at 07:53
  • first in `viewDidLoad` put the first line and in `viewDidAppear` method put the rest of code but use the `[UIView animateWithDuration:.5 animations:^{//IF part or to show} completion:^(BOOL finished){//Else part or to hide}];` code to do the animation automatically you can set the duration as you need in place of `.5` :) – The iOSDev Aug 07 '12 at 09:48
0

OK. As you want to add your subViews (not the container view - I had predicted it through your question!) with sliding animation follow the steps -

  1. Create IBOutlet for your button and textview
  2. synethesize them in .m file.
  3. Write following code -

        - (void)viewWillAppear:(BOOL)animated
    {
    
        self.btn.center = CGPointMake(-430.0, 211.0);
    
        self.txtView.center = CGPointMake(-430.0, 120.0);
    
        [self addSubview:self.btn andMoveTo:CGPointMake(115.0, 211.0) duration:1.0 option:UIViewAnimationOptionCurveLinear];
    
        [self addSubview:self.txtView andMoveTo:CGPointMake(40.0, 34.0) duration:1.0 option:UIViewAnimationOptionCurveLinear];
    
    }
    
    
    - (void) addSubview:(UIView*)view 
              andMoveTo:(CGPoint)destination 
               duration:(float)secs 
                 option:(UIViewAnimationOptions)option
     {
        [UIView animateWithDuration:secs delay:0.0 options:option
                    animations:^{
                        view.frame = CGRectMake(destination.x,destination.y, view.frame.size.width, view.frame.size.height);
                            }completion:nil];
        [self.view addSubview:view];
    
    }
    
Nayan
  • 3,014
  • 2
  • 17
  • 33