2010-12-06 6 views
3

Je dois créer un UIView et extensible pliable de quelque sorte et ne suis pas en mesure de payer pour un contrôle tiers.Comment créer un UIView pliable

C'est fondamentalement la façon dont je voudrais se comporter:

Au sommet, il devrait y avoir un UIButton (ou similaire) qui permet à l'utilisateur de basculer entre élargi et effondré.

Quand élargi Je veux être en mesure de placer d'autres UIView (par exemple le calendrier) et lorsque les contrôles sont effondrés environnants doivent se déplacer vers le haut.

Est-ce que quelqu'un a des idées sur la façon de mettre en œuvre ce simplement - Noob ici :(

Répondre

7

un ViewController et Sous avoir deux méthodes que votre bouton peut tirer comme « l'effondrement » et « élargir », cela pourrait vous aider à démarrer: vous pouvez attribuer de nouveaux sélecteurs à UIButtons dynamiquement:

[button addTarget:self action:@selector(eventMethod:) 
    forControlEvents:UIControlEventTouchUpInside]; 

code:

#define COLAPSED_HEIGHT 30 

-(void)expand 
    { 
     CGRect s= [self getScrerenBoundsForCurrentOriantation]; 
     CGRect f = self.view.frame; 
     f.origin.y =s.size.height-self.view.frame.size.height; 
     [UIView beginAnimations:@"expand" context:NULL]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];  
     self.view.frame=f; 

      //CHANGE YOUR EXPAND/COLLAPSE BUTTON HERE 

     [UIView commitAnimations]; 
     self.thumbScrollerIsExpanded=YES; 
    } 

    -(void)collapseView 
    { 
     //re-factored so that this method can be called in ViewdidLoad 
     CGRect s= [self getScrerenBoundsForCurrentOriantation]; 
     CGRect f = self.view.frame; 

     f.origin.y =(s.size.height-COLAPSED_HEIGHT); 

     self.view.frame = f; 

     self.thumbScrollerIsExpanded=NO; //thumbScrollerIsExpanded is a BOOL property 
    } 


    - (void)collapse 
    {  
     [UIView beginAnimations:@"collapse" context:NULL]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];  
     [self collapseView]; 
      //CHANGE YOUR EXPAND/COLLAPSE BUTTON HERE  
     [UIView commitAnimations]; 

    } 


-(CGRect)getScrerenBoundsForCurrentOriantation 
{ 
    return [self getScrerenBoundsForOriantation:[[UIDevice currentDevice] orientation]]; 
} 


-(CGRect)getScrerenBoundsForOriantation:(UIInterfaceOrientation)_orientation 
{ 
    UIScreen *screen = [UIScreen mainScreen]; 
    CGRect fullScreenRect = screen.bounds; // always implicitly in Portrait orientation.   

    if (UIInterfaceOrientationIsLandscape(_orientation)) 
    { 
     CGRect temp; 
     temp.size.width = fullScreenRect.size.height; 
     temp.size.height = fullScreenRect.size.width; 
     fullScreenRect = temp;  
    } 

    return fullScreenRect; 
} 

- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context 
{ 

    if ([animationID isEqualToString:@"expand"]) 
    { 
    //example 
    } 
else if ([animationID isEqualToString:@"collapse"]) 
    { 
    //example 
    } 
} 
0

vous pouvez essayer d'ajouter un UIView (dans xib ou par programme) hors scr Ensuite, utilisez une animation UIView pour la faire glisser dans votre zone de visualisation principale.

Le bouton aurait un IBAction qui basculer l'animation (slide in/glisser). Vous pouvez le faire glisser hors de l'écran, puis définissez la propriété cachée de UIView sur true. Lorsque vous rappelez l'IBAction, demandez-lui de vérifier si la propriété cachée de la vue est vraie. Si c'est le cas, vous savez jouer l'animation en glissant dedans, sinon, vous jouez l'animation de glisser.

Questions connexes