Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Cross-Platform-Entwicklung (https://www.delphipraxis.net/91-cross-platform-entwicklung/)
-   -   iOS iOS: AnimationDelegate: Events richtig hinzufügen??? (https://www.delphipraxis.net/181042-ios-animationdelegate-events-richtig-hinzufuegen.html)

romber 9. Jul 2014 19:33


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:
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?


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:13 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz