【问题标题】:Change frame in startDeviceMotionUpdatesToQueue更改 startDeviceMotionUpdatesToQueue 中的帧
【发布时间】:2013-06-14 23:44:53
【问题描述】:

我正在尝试使用从 CMMotionManager 及其方法获得的值更改我的 UIView 的框架 - startDeviceMotionUpdatesToQueue:withHandler

我写了这样的草稿:

[_motionManager startDeviceMotionUpdatesToQueue:theQueue withHandler:^(CMDeviceMotion *motion, NSError *error) {
        CGRect frame = _backgroundView.frame;
        double x = motion.attitude.roll;
        frame.origin.x = x*10;
        [_backgroundView setFrame:frame];
}];

但我的观点根本不动。如果我记录我的框架,我可以在每次更新时看到变化......那么为什么我的视图没有在屏幕上移动?

【问题讨论】:

    标签: ios objective-c core-motion cmmotionmanager


    【解决方案1】:

    您在使用情节提要吗?问题可能是由于 Storyboard 中设置的约束覆盖了帧更改。

    通过代码更改自动布局约束,然后尝试上面的框架更改。

    要强制更改,可以在帧更改后使用 - (void)setNeedsLayout 方法。

    【讨论】:

      猜你喜欢
      • 2012-04-09
      • 1970-01-01
      • 2015-11-11
      • 2022-06-28
      • 2013-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多