OGeek|极客世界-中国程序员成长平台

标题: ios - CGAffineTransform Identity 与 iOS 8 和 XCode 6 不同(没有自动布局) [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:07
标题: ios - CGAffineTransform Identity 与 iOS 8 和 XCode 6 不同(没有自动布局)

我有一个动画来添加一个 subview ,使它看起来好像来自用户触摸的内部,然后填满整个屏幕。

同样,当 iOS 应用从用户触摸的地方打开时..

- (void) showView : (UIView *) theview : (CGPoint) thepoint {
    CGPoint c = thepoint;
    CGFloat tx = c.x - floorf(theview.center.x) + 10;
    CGFloat ty = c.y - floorf(theview.center.y) + 100;

    [UIView animateWithDuration:0.5
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         // Transforms
                         CGAffineTransform t = CGAffineTransformMakeTranslation(tx, ty);
                         t = CGAffineTransformScale(t, 0.1, 0.1);
                         theview.transform = t;
                         theview.layer.masksToBounds = YES;
                         [theview setTransform:CGAffineTransformIdentity];

                     }
                     completion:^(BOOL finished) {
                     }];
}

上面的代码做了,直到iOS8..在XCode5.1(iOS7 SDK)下构建

但从 iOS8 SDK、XCode6 开始,行为完全不同

ZOOM 现在的行为很奇怪。我终于能够发现 iOS8 中的 CGAffineTransformIdentity 行为错误(或者我使用错误?)..

我看到很多人都有这个问题,但他们提到了 AutoLayout。我所有的 View 都是以编程方式创建的。我们不使用 nib 文件。(IB)

如何使用 XCode 6 进行这项工作?



Best Answer-推荐答案


经过几个小时的努力,我想出了一个解决方案。我只是将它发布给 future 的用户。

- (void) showView : (UIView *) theview : (CGPoint) thepoint {

    CGPoint c = thepoint;
    CGFloat tx = c.x - (floorf(theview.center.x)) ;
    CGFloat ty = c.y - (floorf(theview.center.y));

    /* The transformation now  is before the animation block */
    CGAffineTransform t = CGAffineTransformMakeTranslation(tx, ty);
    t = CGAffineTransformScale(t, 0.1, 0.1);
    theview.transform = t;
    theview.layer.masksToBounds = YES;

    /* Animate only the CGAffineTransformIdentity */
    [UIView animateWithDuration:0.8
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^{
                                    theview.layer.masksToBounds = YES;
                                    [theview setTransform:CGAffineTransformIdentity];
                                  }
                     completion:^(BOOL finished) {
                          }];
}

但我不知道,为什么它以前适用于 iOS7 SDK 而不是新的 iOS8 SDK。!

关于ios - CGAffineTransform Identity 与 iOS 8 和 XCode 6 不同(没有自动布局),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26409849/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4