Ich habe eine Anmeldeseite namens "LoginViewController". Ich habe auf dieser Seite eine Info-Schaltfläche. Wenn ich darauf klicke, möchte ich einige Informationen zu meiner Bewerbung anzeigen. Ich möchte auch diese Informationsseite mit Flip-Animation präsentieren.
Der Code zum Erstellen der Info-Schaltfläche lautet
infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
infoButton.frame = CGRectMake(285, 425, 30, 30);
infoButton.backgroundColor = [UIColor clearColor];
[infoButton addTarget:self
action:@selector(displayInfoView)
forControlEvents:UIControlEventTouchUpInside];
Wenn ich auf die Info-Schaltfläche klicke, wird die displayInfoView
-Methode aufgerufen. Dort kann ich eine UIView
anzeigen, um einige Informationen anzuzeigen. Habe ich recht?
Für die Flip-Animation habe ich diesen Code verwendet ...
[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];
Hier ist loginPageView
die Login-Ansicht, die die Info-Schaltfläche enthält. infoView
ist die Ansicht, die die Informationen zur Anwendung enthält. mainView
ist die allgemeine Ansicht, die die aktuelle Ansicht enthält.
Nun ist es mein Problem, anstatt eine UIView
anzuzeigen, kann ich eine andere View-Controller-Klasse anzeigen, während ich auf die Info-Schaltfläche klicke? Denken Sie daran, dass die Flip-Aktion mit UIView
funktioniert. Aber wenn ich es mit einer UIViewController
probiere, macht das Ärger.
Kann mir jemand vorschlagen, wie ich einen UIViewController anzeigen soll (in meiner App muss ich AboutViewController
anzeigen), während ich auf den Info-Button mit dem Flip-Effekt klicke?
So wechseln Sie in einen View-Controller:
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:viewController animated:YES completion:nil];
Um es herauszuschlagen:
[self dismissViewControllerAnimated:YES completion:nil];
So mache ich es:
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];
Kredit geht an Faysar hier .
Ihr Verständnis der MVC-Struktur in Cocoa Touch weist einen grundlegenden Fehler auf. View-Controller und Views sind vergleichbar und ähnlich. Die Wahrheit ist, sie sind nicht.
Zurück zu Ihrer spezifischen Frage, ja, Animationen basieren auf Ansichten, nicht auf Ansichtscontrollern. Jede Ansicht sollte jedoch von einem Ihrer View-Controller gesteuert werden. Und diese Ansicht, zu der-Controller-Sache gehört, liegt ganz bei Ihnen. In Ihrem Fall können Animationen zwischen zwei Ansichten mit zwei verschiedenen Controllern oder zwischen zwei Ansichten desselben Controllers auftreten.
Für Codebeispiele empfehle ich Ihnen, eine der Standardvorlagen von Xcode, die Utility Application, zu betrachten, die diese Click-and-Flip-Animation auf eine kurze und standardisierte Weise implementiert hat.
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)
}
einfache Codezeilen
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];