我的应用中有一个媒体播放器,它在视图控制器中持续存在,并试图让用户将其关闭,如下图所示:
我在播放器中添加了UIPanGestureRecognizer
。当平移状态改变时,我可以如下计算θ:
θ = Arctan(opposite/adjacent)
其中相邻的是anchorPoint.x - initialTouchLocation.x
,相反的是translation.y
在我UIPanGestureRecognizer
的{{1}}中,我正在拍摄播放器,将快照的帧设置为实际播放器的帧,并将其添加到超级视图中。然后我根据推荐的here
在UIGestureRecognizerStateBegan
中,我只是计算θ并相应地旋转快照。
这是UIGestureRecognizerStateChanged
动作中的内容:
UIPanGestureRecognizer
但是一旦我试图平移播放器,代表实际视图旋转的快照就会消失。
我尝试在Reveal中查找播放器快照,显然它已添加到视图层次结构中,但我无法在屏幕上的任何位置找到它。
只是想知道是否有人可以帮我修复此问题,或者指出有关此问题的内容。
修改
在我应用旋转变换后,我将- (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: {
}
}
}
放在我的NSLog(@"%@", NSStringFromCGRect(self.playerSnapshot.frame));
中,观察了一些我无法解释的内容
UIGestureRecognizerStateChanged
播放器快照的来源移出屏幕!但我仍然不知道为什么会这样。
答案 0 :(得分:0)
想通了,我错误地设置了anchorPoint。我应该将其设置为相对点,如:
[self setAnchorPoint:CGPointMake(relativePlayerAnchorPoint, 0) forView:playerView];
和relativePlayerAnchorPoint = 0.8f