美文网首页复制粘贴iOS技能iOS
iOS 实现桌面壁纸透视功能

iOS 实现桌面壁纸透视功能

作者: L泽 | 来源:发表于2016-11-04 17:17 被阅读657次

    大家都知道iPhone的桌面和锁屏界面设置的时候有两个按钮,一个是静止,一个是透视。

    就如下图所示

    静止不用说了就是将一张imageView贴上去就行了。但是透视功能就需要用到iPhone的加速器这种硬件的功能了。透视是一个很不错的功能,能够让人对手机的动态效果有一个全新的定义。我再上传两张手机水平放置和竖直放置对比图。

    看一下初音的下巴你就可以很明显感受到壁纸变动了。

    接下来就是用代码改变世界了。


    - (void)startMotionEffects {

    UIInterpolatingMotionEffect *motionX = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];

    UIInterpolatingMotionEffect *motionY = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];

    motionX.minimumRelativeValue = @-15.0;(15就是透视的幅度可自定)

    motionX.maximumRelativeValue = @15.0;

    motionY.minimumRelativeValue = @-15.0;

    motionY.maximumRelativeValue = @15.0;

    UIMotionEffectGroup * motionGroup = [[UIMotionEffectGroup alloc] init];

    motionGroup.motionEffects =@[motionX, motionY];

    [yourImageView addMotionEffect:motionGroup];(yourImageView就是你想让动态改变的image)

    }

    很简单吧 希望你们喜欢。。。。。


    在顺便说一下图标上下抖动吧。这种功能有时候很有用 ,可以瞬间吸引到用户的注意。废话不说上代码


    _wiggleCount = 0;

    - (void)wiggle {

    if (_wiggleCount++ > 10) return;

    [UIView animateWithDuration:0.25f animations:^{

    _button.center = CGPointMake(_button.center.x, _button.center.y + 10.f);

    } completion:^(BOOL finished) {

    [UIView animateWithDuration:0.25f animations:^{

    _button.center = CGPointMake(_button.center.x, _button.center.y - 10.f);

    }];

    }];

    [self performSelector:@selector(wiggle) withObject:nil afterDelay:1.0f];

    }


    哈哈哈 是不是有一种被骗的感觉,那就对了

    相关文章

      网友评论

        本文标题:iOS 实现桌面壁纸透视功能

        本文链接:https://www.haomeiwen.com/subject/yelwuttx.html