Il UIKeyboardAnimationCurveUserInfoKey
ha un valore UIViewAnimationCurve
. Come faccio a convertirlo nel valore UIViewAnimationOptions
corrispondente per l'utilizzo con l'argomento options
di +[UIView animateWithDuration:delay:options:animations:completion:]
?iOS: Come convertire UIViewAnimationCurve in UIViewAnimationOptions?
// UIView.h
typedef enum {
UIViewAnimationCurveEaseInOut, // slow at beginning and end
UIViewAnimationCurveEaseIn, // slow at beginning
UIViewAnimationCurveEaseOut, // slow at end
UIViewAnimationCurveLinear
} UIViewAnimationCurve;
// ...
enum {
// ...
UIViewAnimationOptionCurveEaseInOut = 0 << 16, // default
UIViewAnimationOptionCurveEaseIn = 1 << 16,
UIViewAnimationOptionCurveEaseOut = 2 << 16,
UIViewAnimationOptionCurveLinear = 3 << 16,
// ...
};
typedef NSUInteger UIViewAnimationOptions;
Ovviamente, ho potuto creare un semplice metodo di categoria con una dichiarazione switch
, in questo modo:
// UIView+AnimationOptionsWithCurve.h
@interface UIView (AnimationOptionsWithCurve)
@end
// UIView+AnimationOptionsWithCurve.m
@implementation UIView (AnimationOptionsWithCurve)
+ (UIViewAnimationOptions)animationOptionsWithCurve:(UIViewAnimationCurve)curve {
switch (curve) {
case UIViewAnimationCurveEaseInOut:
return UIViewAnimationOptionCurveEaseInOut;
case UIViewAnimationCurveEaseIn:
return UIViewAnimationOptionCurveEaseIn;
case UIViewAnimationCurveEaseOut:
return UIViewAnimationOptionCurveEaseOut;
case UIViewAnimationCurveLinear:
return UIViewAnimationOptionCurveLinear;
}
}
@end
Ma, c'è un modo ancora più facile/migliore?
Come faccio? Pensavo che LLVM converta automaticamente i metodi Objective-C in funzioni inline quando possibile. – ma11hew28
Sembra che qualcun altro abbia già risposto alla tua domanda: http://stackoverflow.com/questions/8194504/does-llvm-convert-objective-c-methods-to-inline-functions –
Ho aggiunto la versione inline alla mia risposta. –