这里是 iOS 新手,但经过一些谷歌搜索和观看教程后,我似乎无法弄清楚我哪里搞砸了。我将尝试提供尽可能多的信息,我已经在 UIViewController 子类(根 Controller )中为 UIMotionEffect 编写了一些代码。我的 Storyboard包含一个 UIViewcontroller 子类(如下),其 View 包含一个 UIImageView,即代码中的 IBOutlet。一切都在运行,我的调试器点击了 viewDidLoad: 方法,但移动我的手机根本不会移动图像。任何帮助,将不胜感激!感谢您的阅读。
- (void)viewDidLoad
{
[super viewDidLoad];
CGFloat leftRightMin = -55.0f;
CGFloat leftRightMax = 55.0f;
UIInterpolatingMotionEffect *leftRight = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
leftRight.minimumRelativeValue = @(leftRightMin);
leftRight.maximumRelativeValue = @(leftRightMax);
UIMotionEffectGroup *moGroup = [[UIMotionEffectGroup alloc] init];
moGroup.motionEffects = @[leftRight];
[bgImageView addMotionEffect:moGroup];
}
在我的同一个类的头文件中...
@interface TabletMenuViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *bgImageView;
@end
最佳答案
啊哈,根据发行说明,视差和其他一些类似功能在 iPhone 4 上不可用。看来我的开发手机太旧了,而且坏了。
关于iphone - UIMotionEffect 在应用于 View 时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20820703/