UIInterpolatingMotionEffect

iOS7以后增加視差效果,可通過UIInterpolatingMotionEffect類實現(xiàn)此效果。

它有4個property:

keyPath:左右翻轉(zhuǎn)屏幕將要影響到的屬性,比如center.x。
type:(UIInterpolatingMotionEffectType類型),觀察者視角,也就是屏幕傾斜的方式,目前區(qū)分水平和垂直兩種方式。
minimumRelativeValuemaximumRelativeValuev:keyPath對應(yīng)的值的變化范圍,注意這個是id類型。min對應(yīng)最小的offset,max對應(yīng)最大的offset。視差的范圍

代碼如下:

        UIInterpolatingMotionEffect *motionEffect;
        motionEffect = [[UIInterpolatingMotionEffect alloc]initWithKeyPath:@"center.x"
                                                                      type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
        motionEffect.minimumRelativeValue = @(-25);
        motionEffect.maximumRelativeValue = @(25);
        [messageLabel addMotionEffect:motionEffect];
        
        motionEffect = [[UIInterpolatingMotionEffect alloc]initWithKeyPath:@"center.y"
                                                                      type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
        motionEffect.minimumRelativeValue = @(-25);
        motionEffect.maximumRelativeValue = @(25);
        [messageLabel addMotionEffect:motionEffect];

此功能需要在真機上才能體現(xiàn)。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容