Animated Subviews

Discussion in 'iOS Programming' started by ashwinr87, Jun 14, 2011.

  1. ashwinr87 macrumors member

    Joined:
    Mar 9, 2011
    #1
    I have a split view controller in my Ipad app, in which the detail view has subviews which are UITableView's. The functionality I am trying to implement is to get an info view at the same position of a subview when a button(info button) on the subview is pressed. I need to get this info view by animation and that animation is that when the info button is pressed, that subview alone would flip (UIAnimationOptionFlipFromRight) and the info view would show...

    This is how try to implement it -

    Code:
    -(void) showInfoView: (id)sender
    {
    
        infoView = [[InfoViewController alloc] initWithNibName:@"ViewViewController" bundle:nil];
        infoView.view.frame = CGRectMake(250, 300, 200, 200);
    
        [UIView transitionWithView:self.view duration:1
                           options:UIViewAnimationOptionTransitionFlipFromRight 
                        animations:^{
                            [self.view addSubview:infoView.view];
                        } 
                        completion:nil];
    }
    When I run the simulator and press the info button on any subview, what happens is that the animation happens perfectly, i.e. the subview flips from the right but the infoView is not getting displayed.

    It would be great if someone could tell me where I am going wrong here.
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    Why don't you just add it as a modalviewcontroller which flips from the right? it's alot easier :)
    About your code.

    Code:
    infoView = [[InfoViewController alloc] initWithNibName:@"ViewViewController" bundle:nil];
        infoView.view.frame = CGRectMake(250, 300, 200, 200);
    
        [UIView transitionWithView:self.view duration:1
                           options:UIViewAnimationOptionTransitionFlipFromRight 
                        animations:^{
                            [self.view addSubview:infoView.view];
                        } 
                        completion:nil];
    I guess your "infoView variable" is a pointer to InfoViewController.

    Id go for
    Code:
    InfoViewController *infoVC = [[InfoViewController alloc] initWithNibName:@"InfoViewController" bundle:nil];
    // MAKE SURE U USE THE RIGHT NAME + CASE SENSITIVE
    
    The rest of the code is fine I think, I think the error is, in adding the subview. with the correct view.
     
  3. ashwinr87 thread starter macrumors member

    Joined:
    Mar 9, 2011
    #3
    Thanks for the reply.. I already have put InfoViewController *infoView in my .h file and have included infoView in the synthesize in my .m file.. both the methods are the same right?

    Btw, I also tried out in the way you said but still the info view is not getting displayed...

     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    No need to make it a property, an instance variable is enough.
    I think the error is within the
    "[self.view addSubview:infoView.view];"

    It's not adding it at the right moment.
    Why don't you just present it as a modalviewcontroller?

    Like this :)

    Code:
        LoginScreenController *loginController = [[LoginScreenController alloc] initWithNibName:@"LoginScreenController" bundle:nil];
    	[loginController setModalPresentationStyle:UIModalPresentationFullScreen];
        [loginController setModalTransitionStyle:UIModalTransitionStylePartialCurl];
        [self presentModalViewController:loginController animated:YES];
        [loginController release];
    With this it will be presented as a partial curl, just try playing with UIModalTransitionStylePartialCurl, like this -->
    UIModalTransitionStyleFlipHorizontal
     
  5. ashwinr87 thread starter macrumors member

    Joined:
    Mar 9, 2011
    #5
    Thanks for the reply..
    I want to view to come directly at the same position of the UITableView(on which I press the info button).. when I display the view using modalviewcontroller, it gets displayed at the middle of the screen... is it possible for me to move the position of the subview(presented as a modal view controller)?

     
  6. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #6
    No, you can't change the position of the modalviewController. Then you need a subview indeed.
    But I think the problem is, you're trying to show it in a class, which doesn't want to show it sort of speech. It's hard to go on, without more code then.
     

Share This Page