iOS7以后增加視差效果,可通過UIInterpolatingMotionEffect類實現(xiàn)此效果。
它有4個property:
keyPath:左右翻轉(zhuǎn)屏幕將要影響到的屬性,比如center.x。
type:(UIInterpolatingMotionEffectType類型),觀察者視角,也就是屏幕傾斜的方式,目前區(qū)分水平和垂直兩種方式。
minimumRelativeValue和maximumRelativeValuev: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)。