Registriert seit: 15. Apr 2004
Ort: Köln
1.166 Beiträge
Delphi 10 Seattle Professional
|
iOS: AnimationDelegate: Events richtig hinzufügen???
9. Jul 2014, 20:33
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:
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;
Das Problem liegt definitiv an der Code, mit dem ich der UIView-Classe die Events hinzufüge:
Delphi-Quellcode:
TUIView.OCClass.setAnimationWillStartSelector(Sel_getUid('statusBarAnimationSelector:context:'));
TUIView.OCClass.setAnimationDidStopSelector(Sel_getUid('openMenuAnimationDidStop:finished:context:'));
TUIView.OCClass.setAnimationDidStopSelector(Sel_getUid('closeMenuAnimationDidStop:finished:context:'));
Was mache ich falsch?
Geändert von romber ( 9. Jul 2014 um 20:35 Uhr)
|
|
Zitat
|