El UIKeyboardAnimationCurveUserInfoKey
tiene un valor de UIViewAnimationCurve
. ¿Cómo lo convierto al valor UIViewAnimationOptions
correspondiente para usar con el argumento options
del +[UIView animateWithDuration:delay:options:animations:completion:]
?iOS: ¿Cómo convertir UIViewAnimationCurve a 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;
Obviamente, podría crear un método simple categoría con una declaración switch
, así:
// 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
Pero, ¿hay una manera mejor/más fácil?
¿Cómo hago eso? Pensé que LLVM convierte automáticamente los métodos Objective-C en funciones en línea cuando es posible. – ma11hew28
Parece que alguien más ya respondió su pregunta: http://stackoverflow.com/questions/8194504/does-llvm-convert-objective-c-methods-to-inline-functions –
Agregué la versión en línea a mi respuesta. –