0

我的应用程序中有一个媒体播放器,它跨视图控制器持续存在,并试图让用户将其关闭,如下图所示:

在此处输入图像描述

我在UIPanGestureRecognizer我的播放器中添加了一个。当平移状态发生变化时,我可以计算 θ 如下:

θ = Arctan(opposite/adjacent)

其中相邻是anchorPoint.x - initialTouchLocation.x,对面是translation.y

在我UIPanGestureRecognizer的 's UIGestureRecognizerStateBegan中,我正在对播放器进行快照,将快照的帧设置为实际播放器的帧,并将其添加到超级视图中。然后我根据这里推荐的内容更改快照的锚点

在 中UIGestureRecognizerStateChanged,我只是在计算 θ 并相应地旋转快照。

这是我的UIPanGestureRecognizer实际行动:

- (void)playerMovedDown:(UIPanGestureRecognizer *)recognizer {
    CGPoint translation = [recognizer translationInView:self.playerView];

    CCPlayer *playerView = (CCPlayer *) recognizer.view;
    switch (recognizer.state) {
        case UIGestureRecognizerStateBegan: {
            _adjacent = self.playerAnchorPoint.x - translation.x;


            self.playerSnapshot = [playerView snapshotViewAfterScreenUpdates:NO];
            [playerView.superview addSubview:self.playerSnapshot];
            self.playerSnapshot.frame = playerView.frame;

            [playerView.superview sendSubviewToBack:playerView];
            [playerView.superview bringSubviewToFront:self.playerSnapshot];


            [self setAnchorPoint:CGPointMake(self.playerOriginalFrame.size.width * relativePlayerAnchorPoint,
                0) forView:playerView];
        }

        case UIGestureRecognizerStateChanged : {
            _opposite = translation.y;
            CGFloat angel = atan2f(_opposite, _adjacent);
            self.playerSnapshot.transform = CGAffineTransformMakeRotation (-angel);
            NSLog(@"%@", NSStringFromCGRect(self.playerSnapshot.frame));
        }
        default: {

        }
    }
}

但是一旦我试图平移播放器,应该代表实际视图旋转的快照就会消失。

我尝试在Reveal中查找播放器快照,显然它已添加到视图层次结构中,但我在屏幕的任何地方都找不到它。

只是想知道是否有人可以帮助我解决这个问题,或者指出一些关于这个问题的东西。

编辑: 我在应用旋转变换后放入NSLog(@"%@", NSStringFromCGRect(self.playerSnapshot.frame)); 我的UIGestureRecognizerStateChanged,并观察到一些我无法解释的东西

{{7602.2540144175437, 34747.255839671474}, {353.40894445994036, 270.70438804942387}}
{{7677.5559653403761, 34908.541487295603}, {353.41127718399275, 271.19899878758588}}
{{7764.1261318069446, 35092.834523913771}, {353.41188643557598, 271.76320186068915}}
{{7801.1330694789358, 35171.252487591031}, {353.41147875381648, 272.00296155658725}}
{{7844.4014697306702, 35262.665288048178}, {353.41049980147181, 272.28221631572524}}

玩家快照的原点已移出屏幕!但我仍然不知道为什么会这样。

4

1 回答 1

0

想通了,我错误地设置了锚点。我应该将其设置为一个相对点,例如:

[self setAnchorPoint:CGPointMake(relativePlayerAnchorPoint, 0) forView:playerView];

relativePlayerAnchorPoint = 0.8f

于 2014-08-03T04:51:14.823 回答