How to animate when no reference to target view?

Discussion in 'iOS Programming' started by Earl Grey, Dec 7, 2011.

  1. Earl Grey, Dec 7, 2011
    Last edited by a moderator: Dec 8, 2011

    Earl Grey macrumors newbie

    Joined:
    Nov 30, 2011
    #1
    Hi,

    In my iOS5 app for iPhone, I have something like this

    AppDelegate
    ivar ViewController1
    ivar ViewController2


    ViewController1
    ivar view1
    ivar button1
    IBAction animateToView


    ViewController2
    ivar view2


    Now I want to animate from view1 from viewcontroller1 to view2 from viewcontroller2 by pushing a button in viewcontroller1.
    Bu I do not have a reference to the view2 to the viewcontroller2 in viewcontroler1.

    If I hook the button to an action/target and use block based animation in it
    this one >>

    Code:
        [UIView transitionFromView:<#(UIView *)#> 
                            toView:<#(UIView *)#> 
                          duration:<#(NSTimeInterval)#> 
                           options:<#(UIViewAnimationOptions)#> 
                        completion:<#^(BOOL finished)completion#>]
    
    I am unable to fill in the toView: because of those missing references.

    What would you recommend? IS it even good to solve thi by action target?

    Thanks.
     
  2. jnoxx, Dec 7, 2011
    Last edited by a moderator: Dec 8, 2011

    jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    What I'd recommand, is make a category on your UIViewController, call it transitions, or whatever.
    Code something in there to make your sliding in terms like

    Code:
    - (void) SlideToNextViewController:(UIViewController*)theViewController {
     //Animations go here. like, self.navigationController push Blah.
     }
    Then call that in view 1.
    Make a pointer to your second view you are transferring to, just give the pointer to your method from your category, and it should be fine.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    transitionFromView:toView: is meant for animating view transitions within the same view controller. If you wish to animate to another view controller's view, perhaps consider presentModalViewController: in conjunction with modalTransitionStyle.
     

Share This Page