![]() |
iOS: AnimationDelegate: Events richtig hinzufügen???
Hallo!
Ich versuche einer Animation zwei Events für BeginAnimation- und EndAnimation hinzu zu fügen. Auf dem Gerät klappt alles wunderbar, nur im Simulator sturzt die App ab. Hier der Code:
Delphi-Quellcode:
Das Problem liegt definitiv an der Code, mit dem ich der UIView-Classe die Events hinzufüge:
type
id = Pointer; SEL = Pointer; PNSString = Pointer; PNSNumber = Pointer; type TMenuEndAnimationType = (maNone, maOpen, maClose); var frmMain: TfrmMain; animationDelegateClass: Pointer; statusBarView: UIView; oldPositionX, newPositionX: Single; ... procedure TfrmMain.FormCreate(Sender: TObject); begin ... //Hier wird AnimationDelegate initialisiert animationDelegateClass := objc_allocateClassPair(objc_getClass('NSObject'), 'DelphiAnimationDelegate', 0); class_addMethod(animationDelegateClass, sel_getUid('openMenuAnimationDidStop:finished:context:'), @openMenuAnimationDidStop, 'v@:@@@'); class_addMethod(animationDelegateClass, sel_getUid('closeMenuAnimationDidStop:finished:context:'), @closeMenuAnimationDidStop, 'v@:@@@'); class_addMethod(animationDelegateClass, sel_getUid('statusBarAnimationSelector:context:'), @statusBarAnimationSelector, 'v@:@@'); objc_registerClassPair(animationDelegateClass); ... end; //Hier die neuen Methoden procedure openMenuAnimationDidStop(self: id; _cmd: SEL; animationID: PNSString; finished: PNSNumber; context: CGContextRef); begin statusBarView.setAlpha(1); TUIApplication.Wrap(TUIApplication.OCClass.sharedApplication).setStatusBarStyle(UIStatusBarStyleLightContent, false); end; procedure closeMenuAnimationDidStop(self: id; _cmd: SEL; animationID: PNSString; finished: PNSNumber; context: CGContextRef); begin statusBarView.setAlpha(0); TUIApplication.Wrap(TUIApplication.OCClass.sharedApplication).setStatusBarStyle(UIStatusBarStyleDefault, false); end; procedure statusBarAnimationSelector(self: id; _cmd: SEL; animationID: PNSString; context: CGContextRef); begin TUIView.OCClass.beginAnimations(nil, nil); TUIView.OCClass.setAnimationDuration(0.2); statusBarView.setAlpha(oldPositionX / 1.7 * 0.01); statusBarView.setAlpha(newPositionX / 1.7 * 0.01); TUIView.OCClass.commitAnimations; end; //Und hier liegt das Problem procedure TfrmMain.OpenCloseMenu(const X_From, X_To, Y_From, Y_To: Single; const W_From, W_To, H_From, H_To, AAnimationDuration: Extended; AEndAnimation: TMenuEndAnimationType = maNone); begin oldPositionX := X_From; newPositionX := X_To; TUIView.OCClass.beginAnimations(nil, nil); TUIView.OCClass.setAnimationDuration(AAnimationDuration); TUIView.OCClass.setAnimationDelegate(@animationDelegateClass); TUIView.OCClass.setAnimationWillStartSelector(Sel_getUid('statusBarAnimationSelector:context:')); // <---Hier stürzt der Simulator ab case AEndAnimation of maOpen: TUIView.OCClass.setAnimationDidStopSelector(Sel_getUid('openMenuAnimationDidStop:finished:context:')); // <---oder hier maClose: TUIView.OCClass.setAnimationDidStopSelector(Sel_getUid('closeMenuAnimationDidStop:finished:context:')); // <---oder hier end; ApplicationView.FUIViewController.view.setFrame(CGRectMake(X_From, Y_From, W_From, H_From)); ApplicationView.FUIViewController.view.setFrame(CGRectMake(X_To, Y_To, W_To, H_To)); TUIView.OCClass.commitAnimations; end;
Delphi-Quellcode:
Was mache ich falsch?
TUIView.OCClass.setAnimationWillStartSelector(Sel_getUid('statusBarAnimationSelector:context:'));
TUIView.OCClass.setAnimationDidStopSelector(Sel_getUid('openMenuAnimationDidStop:finished:context:')); TUIView.OCClass.setAnimationDidStopSelector(Sel_getUid('closeMenuAnimationDidStop:finished:context:')); |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:01 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz