【发布时间】:2014-11-17 01:32:48
【问题描述】:
我对 xcode 还是很陌生。想玩一会儿,却遇到了这种奇怪的行为……
我正在使用 CoreMotion 加速在屏幕上移动图像。
缩短移动 UIImageView 的移动代码...
dispatch_async(dispatch_get_main_queue(), ^{
CGRect recta = movingImage.frame;
//data is the coremotion info.
float dataAccelerationX = data.acceleration.x;
float dataAccelerationY = -data.acceleration.y;
float movetoX = recta.origin.x + (dataAccelerationX * stepMoveFactor);
float maxX = self.view.frame.size.width - recta.size.width;
float movetoY = (recta.origin.y + recta.size.height) - (dataAccelerationY * stepMoveFactor);
float maxY = self.view.frame.size.height;
movingImage.frame = recta;
});
发生这种情况时,我有一个按钮,它只是在现有 UIView 上创建另一个 UIImageView...
-(void)addInAnotherImage
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"making UIImageView with image file");
UIImageView *someImage =[[UIImageView alloc] initWithFrame:CGRectMake(200,200,200,200)];
someImage.image=[UIImage imageNamed:@"someimage.png"];
[self.view addSubview:someImage];
});
}
当这种情况发生时,movingImage 会跳回到它开始的原始位置。我希望实现 addInAnotehrImage 在使用 CoreMotion 加速在屏幕上浮动时触发 addInAnotehrImage。任何人都可以帮助我确定为什么在运行 addInAnotherImage 时,movingImage 会跳回原始位置?
【问题讨论】:
标签: ios objective-c xcode uiimageview core-motion