[iOS]UIInterpolatingMotionEffect重力視覺差

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.view.backgroundColor = [UIColor grayColor];
    
    UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
    view.backgroundColor = [UIColor blueColor];
    view.layer.borderColor = [[UIColor greenColor] CGColor];
    view.layer.borderWidth = 5.0;
    [self.view addSubview:view];
    
    // 建立偏移
    UIInterpolatingMotionEffect *effectX = [[UIInterpolatingMotionEffect alloc]
                                            initWithKeyPath:@"center.x"
                                            type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
    UIInterpolatingMotionEffect *effectY = [[UIInterpolatingMotionEffect alloc]
                                            initWithKeyPath:@"center.y"
                                            type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
    
    // 設置最大值和最小值
    effectX.maximumRelativeValue = @(100);
    effectX.minimumRelativeValue = @(-100);
    effectY.maximumRelativeValue = @(100);
    effectY.minimumRelativeValue = @(-100);
    
    [view addMotionEffect:effectX];
    [view addMotionEffect:effectY];
}

初始效果圖spa

傾斜屏幕後效果圖code

相關文章
相關標籤/搜索