首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >改变UIView AnchorPoint后旋转AnchorPoint

改变UIView AnchorPoint后旋转AnchorPoint
EN

Stack Overflow用户
提问于 2014-08-03 01:24:41
回答 1查看 267关注 0票数 0

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

我给我的球员添加了一个UIPanGestureRecognizer。当pan状态发生变化时,我可以按以下方式计算θ:

θ = Arctan(opposite/adjacent)

相邻的是anchorPoint.x - initialTouchLocation.x,相对的是translation.y

在我的UIPanGestureRecognizerUIGestureRecognizerStateBegan中,我正在快照播放器,将快照的帧设置为实际播放器的框架,并将其添加到超级视图中。

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

下面是我在UIPanGestureRecognizer行动中得到的信息:

代码语言:javascript
复制
- (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中,并观察到一些我无法解释的东西

代码语言:javascript
复制
{{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}}

播放机快照的来源被移离屏幕很远的地方!但我还是不知道为什么会这样。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-03 04:51:14

我想出了问题,我把anchorPoint设置错了。我应该把它设置为一个相对点,例如:

代码语言:javascript
复制
[self setAnchorPoint:CGPointMake(relativePlayerAnchorPoint, 0) forView:playerView];

relativePlayerAnchorPoint = 0.8f

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25100795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档