簡體   English   中英

將NSNotification.userInfo [UIKeyboardAnimationCurveUserInfoKey]轉換為Enum

[英]Convert NSNotification.userInfo[UIKeyboardAnimationCurveUserInfoKey] to Enum

使用NSNotification.userInfo中的NSNumber [UIKeyboardAnimationCurveUserInfoKey]

目標CI將執行以下操作

 [UIView animateWithDuration:1.0
                      delay:0
                    options:(curveValue.intValue << 16)

即使bitshift運算符相同,Swift也不允許我這樣做。 我想獲得相當於枚舉的原始值

UIViewAnimationOptionCurveEaseInOut = 0 << 16,

UIViewAnimationOptionCurveEaseIn = 1 << 16,

UIViewAnimationOptionCurveEaseOut = 2 << 16,

UIViewAnimationOptionCurveLinear = 3 << 16,

更新


我不確定以下方法是否正確,似乎有效

 var animationCurve : UIViewAnimationOptions = UIViewAnimationOptions.CurveEaseOut
 info[UIKeyboardAnimationCurveUserInfoKey].getValue(&animationCurve)


 UIView.animateWithDuration(durationValue.doubleValue,
        delay: 0,
        options: animationCurve,
        animations: {self.navigationController.toolbar.frame = myRect},
        completion: nil)

在Beta-5中

UIViewAnimationOptions.fromRaw(
    UInt(
        ( p.userInfo[ UIKeyboardAnimationCurveUserInfoKey ] as NSNumber ).unsignedIntValue << 16
    )
)!

你必須使用rawValue初始化一個UIViewAnimationOptions,如下所示:

UIView.animateWithDuration(1.0, delay: 0, options: UIViewAnimationOptions.init(rawValue:UInt(curveValue.intValue << 16)),

這是你需要的嗎?

UIViewAnimationCurve.fromRaw(Int(hereGoesYourStuff))
let animationKey = userInfo[UIKeyboardAnimationCurveUserInfoKey] as UInt
UIViewAnimationOptions(rawValue: animationKey)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM