5

Sto provando ad avere una diapositiva di UIView su un quarto della pagina per rivelare un'altra vista al di sotto di essa (per visualizzare le opzioni), quindi scorrere verso il basso per coprire quelle opzioni. Ho cercato così inesorabilmente ma non riesco a trovare quello che sto cercando. Non voglio usare una modalview perché voglio mantenere la vista dall'alto sullo schermo. Nel codice qui sotto, ho una sorta di funzionamento, il livello superiore scorre verso l'alto, ma poi scompare completamente (dissolvenza).Scorri UIView utilizzando kCATransitionPush

Qualsiasi aiuto è molto apprezzato!

Grazie.

HomeOptionsViewController *homeOptionsViewController = [[HomeOptionsViewController alloc] 
         initWithNibName:@"HomeOptionsViewController" 
         bundle:nil]; 
// get the view that's currently showing 
UIView *currentView = self.view; 
// get the the underlying UIWindow, or the view containing the current view 
UIView *theWindow = [currentView superview]; 

UIView *newView = homeOptionsViewController.view; 
//newView.frame = CGRectMake(0,300, 320,140); 
    newView.frame = CGRectMake(0,-10, 320,140); 
// remove the current view and replace with myView1 
//---[currentView removeFromSuperview]; 
[theWindow addSubview:newView]; 

theWindow.frame = CGRectMake(0,-110,320,200); 

newView.frame = theWindow.bounds; 
// set up an animation for the transition between the views 

CATransition *animation = [CATransition animation]; 
[animation setDuration:0.5]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromTop]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
//[theWindow setFrame:CGRectMake(0,200,320,300)]; 
[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"]; 

risposta

3

Qualsiasi motivo per cui non si utilizzano le animazioni standard UIView? CATransitions cambierà completamente la vista perché dovrebbe essere una transizione da una vista all'altra.

Hai provato qualcosa del genere? Si aggiunge la vista che si desidera scorrere appena fuori dalla parte inferiore dello schermo, quindi si animano entrambi i riquadri che cambiano. Crea un effetto slide up.

newView.frame = CGRectMake(0,416,320,140); 
[theWindow addSubview:newView]; 
[UIView beginAnimations:@"SwitchToView1" context:nil]; 
[UIView setAnimationDuration:0.5]; 
theWindow.frame = CGRectOffset(theWindow.frame, 0, -140); 
newView.frame = CGRectOffset(newView.frame, 0, -140); 
[UIView commitAnimations]; 
+0

Grazie Mishie. Nessun motivo particolare per cui ho usato CATransitions se non per dire che non sapevo niente di meglio. Ho provato il tuo codice per utilizzare le UIViews standard, ma non sta ancora fornendo l'effetto desiderato. la vista Finestra fa scorrere verso l'alto, ma il newView appare appena nella parte superiore dello schermo, sopra la vista Finestra e quindi scorre verso il basso. Mi piacerebbe che la vista Finestra scorri verso l'alto e che newView appaia sotto, in basso. Come posso controllare l'animazione usando UIView standard? Grazie! – Doug

+0

Hai solo bisogno di impostare le coordinate del frame correttamente. Non sono sicuro di quale sia stato il frame iniziale del tuo nuovoView, quindi ho solo indovinato =) – MishieMoo

+0

Grazie ancora Mishie. Questo funzionerà. – Doug