ios uiview uiviewcontroller flip

ios - ¿Cómo hacer la animación invertida entre dos UIViewControllers mientras se hace clic en el botón de información?



flip (5)

Tengo una página de inicio de sesión llamada "LoginViewController". Tengo un botón de información en esta página. Si hago clic en él, quiero mostrar información sobre mi aplicación. También quiero presentar esa página de información usando flip animation.

El código para crear el botón de información es,

infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; infoButton.frame = CGRectMake(285, 425, 30, 30); infoButton.backgroundColor = [UIColor clearColor]; [infoButton addTarget:self action:@selector(displayInfoView) forControlEvents:UIControlEventTouchUpInside];

Si hago clic en el botón de información, se displayInfoView método displayInfoView . Ahí puedo mostrar una UIView para mostrar cierta información. ¿Estoy en lo cierto?

Para la animación flip, utilicé este código ...

[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:.8]; [UIView setAnimationTransition:([loginPageView superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) forView:mainView cache:YES]; if ([infoView superview]) { [infoView removeFromSuperview]; [mainView addSubview:loginPageView]; } else { [loginPageView removeFromSuperview]; [mainView addSubview:infoView]; } [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; [UIView commitAnimations];

Aquí loginPageView es la vista de inicio de sesión que contiene el botón de información. infoView es la vista que contiene la información sobre la aplicación. mainView es la vista común que mantiene la vista actual.

Ahora mi problema es que, en lugar de mostrar UIView , ¿puedo mostrar otra clase de controlador de vista mientras hago clic en el botón de información? Recuerde que la acción de volteo funciona bien con UIView . Pero cuando intento con un UIViewController , esto UIViewController problemas.

¿Puede alguien sugerirme cómo mostrar un UIViewController (en mi aplicación, necesito mostrar AboutViewController ) mientras AboutViewController clic en el botón de información con el efecto de tapa?


Así es como lo estoy haciendo:

AboutShowViewController *aboutShowViewController = [[AboutShowViewController alloc] initWithNibName:@"AboutShowViewController" bundle:[NSBundle mainBundle]]; [UIView beginAnimations:@"View Flip" context:nil]; [UIView setAnimationDuration:0.80]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO]; [self.navigationController pushViewController:aboutShowViewController animated:YES]; [UIView commitAnimations]; [aboutShowViewController release];

El crédito va a Faysar here .


Existe un error fundamental en su comprensión de la estructura de MVC en Cocoa Touch, que es, Ver Controladores y Vistas son comparables y similares. La verdad es que no lo son.

De vuelta a su pregunta específica, sí, las animaciones se basan en vistas, no en controladores de vista. Pero cada vista debe ser controlada por uno de sus controladores de vista. Y esta cosa que-vista-pertenece-a-qué-controlador es totalmente de usted. En su caso, la animación podría ocurrir entre 2 vistas con 2 controladores diferentes, o también podrían ocurrir entre 2 vistas del mismo controlador.

En cuanto a las muestras de código, le sugiero que eche un vistazo a una de las plantillas predeterminadas de Xcode, la Aplicación de utilidad , que ha implementado esta animación de clic y lanzamiento de manera breve y estandarizada.


Para voltear en un controlador de vista:

viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentViewController:viewController animated:YES completion:nil];

Para voltearse:

[self dismissViewControllerAnimated:YES completion:nil];


simples líneas de código

YourViewController *city = [self.storyboard instantiateViewControllerWithIdentifier:@"YourViewController"]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.5]; [self.navigationController pushViewController:city animated:YES]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; [UIView commitAnimations];


override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(true) // for back button changeTransition() } //btnMap.addTarget(self, action: #selector(searchHotelsResultVC.goToMap), for: .touchUpInside) //btnMap.addTarget(self, action: #selector(MapViewController.backToList), for: .touchUpInside) func goToMap() { // for pushing changeTransition() navigationController?.pushViewController(settingsVC, animated: false) } func backToList() { // for dismiss changeTransition() navigationController?.popViewController(animated: false) dismiss(animated: true, completion: nil) } func changeTransition() { let transition = CATransition() transition.duration = 0.5 transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) //transition.type = kCATransitionPush transition.type = "flip" transition.subtype = kCATransitionFromLeft navigationController?.view.layer.add(transition, forKey: kCATransition) }