大家都知道iPhone的桌面和鎖屏界面設(shè)置的時(shí)候有兩個(gè)按鈕,一個(gè)是靜止,一個(gè)是透視。
就如下圖所示
靜止不用說了就是將一張imageView貼上去就行了。但是透視功能就需要用到iPhone的加速器這種硬件的功能了。透視是一個(gè)很不錯(cuò)的功能,能夠讓人對(duì)手機(jī)的動(dòng)態(tài)效果有一個(gè)全新的定義。我再上傳兩張手機(jī)水平放置和豎直放置對(duì)比圖。
看一下初音的下巴你就可以很明顯感受到壁紙變動(dòng)了。
接下來就是用代碼改變世界了。
- (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就是你想讓動(dòng)態(tài)改變的image)
}
很簡(jiǎn)單吧 希望你們喜歡。。。。。
在順便說一下圖標(biāo)上下抖動(dòng)吧。這種功能有時(shí)候很有用 ,可以瞬間吸引到用戶的注意。廢話不說上代碼
_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];
}
哈哈哈 是不是有一種被騙的感覺,那就對(duì)了