iOS的8 CGAffineTransformMakeScale +自动版式不再起作用 [英] iOS 8 CGAffineTransformMakeScale + autolayout not working any more

查看:265
本文介绍了iOS的8 CGAffineTransformMakeScale +自动版式不再起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有似乎是一些后与我的问题,但似乎没有任何帮助。 <一href=\"http://stackoverflow.com/questions/12943107/how-do-i-adjust-the-anchor-point-of-a-calayer-when-auto-layout-is-being-used\">How做我调整的CALayer,当正在使用自动布局的锚点?

我有我的应用程序的缩放preVIEW(如教程),该标准视图(和ViewController)按比例缩小,并在另一个视图中显示。

  =============
= =
= = ---------
- - = =
= - preview- =
- - = =
= = ---------
= =查看
=============

为此,我用这个code:

  previewViewController.view.transform = CGAffineTransformMakeScale(规模* 2,规模* 2);

我也需要这个比例观点与教程视图控制器对齐。为此,我创建了一个占位符观,我希望我的缩放以期大小相匹配。

为此,我使用:

   - (无效)setConstraintsFor previewViewController
{
    NSArray的*属性= @ [@(NSLayoutAttributeLeftMargin),@(NSLayoutAttributeRightMargin),@(NSLayoutAttributeTopMargin),@(NSLayoutAttributeBottomMargin)];
    [属性enumerateObjectsUsingBlock:^(*的NSNumber OBJ,NSUInteger IDX,BOOL *停止){
        NSLayoutAttribute属性= [OBJ integerValue]
        [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.viewControllerPlaceholderView
                                                              属性:属性
                                                              relatedBy:NSLayoutRelationEqual
                                                                 toItem:previewViewController.view
                                                              属性:属性
                                                             事半功倍:1
                                                               常数:0]];
    }];
}

这工作好,我的iOS 7,但与X code 6和iOS 8这似乎打破建设。这似乎像现在首先设置约束(调整占位符),然后缩放下来(导致太小preVIEW)。

code:

   - (无效)设置previewViewController
{
    浮规模= [个体经营规模]
    previewViewController = [self.storyboard instantiateViewControllerWithIdentifier:[PLACEHOLDER_VIEWCONTROLLER_NAMES objectAtIndex:self.identifier]];    previewViewController.view.transform = CGAffineTransformMakeScale(规模* 2,规模* 2);    [self.view addSubview:previewViewController.view]。
    previewViewController.view.translatesAutoresizingMaskIntoConstraints = NO;    [个体经营addChildViewController:previewViewController]。    [自setConstraintsFor previewViewController]。    self.viewControllerPlaceholderToImageViewSpaceConstraint.constant =(自hasNavigationBar](44 *刻度* 2):-22 *刻度* 2);    self.viewControllerPlaceholderToBottomSpaceConstraint.constant = IS_WIDESCREEN? 160:131;    previewViewController.view.userInteractionEnabled = NO;    [self.view setNeedsLayout]
}


解决方案

这似乎是在iOS 8的错误给我。我有同样的问题。我的解决办法是禁用自动布局为preVIEW和度假村到autoresizingMask。

  preview.translatesAutoresizingMaskIntoConstraints = YES;
preview.autoresizingMask =(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
preview.frame = view.bounds;

但我的preVIEW视图是一个普通的UIImageView。我不知道它将如何与一些复杂的基于自动布局,preVIEW视图中工作。

我有pretty类似的设置是你的,我使用顶部占位VC也一样,但它的使用autoresizingMask过,好像更容易垂直居中的东西建造的。

如果您使用preVIEW观点和经验问题,里面的任何约束,那么我会试着换preVIEW多一个的UIView,看看它是否工作。 [视图(autoresizingMask,自定义的框架,缩放)] - GT; [查看(autoresizingMask =灵活宽+高)] - GT; [preVIEW(自动布局)]

There seems to be a some post related to my problem but none seems to help. How do I adjust the anchor point of a CALayer, when Auto Layout is being used?

I have a scaled preview of my app (as a tutorial), which the standard view (and viewcontroller) scaled down and shown on another view.

=============
=           =
= --------- =
= -       - =
= -Preview- =
= -       - =
= --------- =
=    View   =
=============

For this I use this code:

previewViewController.view.transform = CGAffineTransformMakeScale(scale*2, scale*2);

I also need this scaled view to align with the tutorial view controller. For this I created a "placeholder view" which I want my scaled view to match in size.

For this I use:

-(void)setConstraintsForPreviewViewController
{
    NSArray *attributes = @[@(NSLayoutAttributeLeftMargin), @(NSLayoutAttributeRightMargin), @(NSLayoutAttributeTopMargin), @(NSLayoutAttributeBottomMargin)];
    [attributes enumerateObjectsUsingBlock:^(NSNumber *obj, NSUInteger idx, BOOL *stop) {
        NSLayoutAttribute attribute = [obj integerValue];
        [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.viewControllerPlaceholderView
                                                              attribute:attribute
                                                              relatedBy:NSLayoutRelationEqual
                                                                 toItem:previewViewController.view
                                                              attribute:attribute
                                                             multiplier:1
                                                               constant:0]];
    }];
}

This worked good i iOS 7, but building with XCode 6 and iOS 8 this seems to break. It seems as it now first sets the constraints (adjust to placeholder) and then scales it down (resulting in a too small preview).

Code:

-(void)setupPreviewViewController
{
    float scale = [self scale];
    previewViewController = [self.storyboard instantiateViewControllerWithIdentifier:[PLACEHOLDER_VIEWCONTROLLER_NAMES objectAtIndex:self.identifier]];

    previewViewController.view.transform = CGAffineTransformMakeScale(scale*2, scale*2);

    [self.view addSubview:previewViewController.view];
    previewViewController.view.translatesAutoresizingMaskIntoConstraints = NO;

    [self addChildViewController:previewViewController];

    [self setConstraintsForPreviewViewController];

    self.viewControllerPlaceholderToImageViewSpaceConstraint.constant = ([self hasNavigationBar] ? (44 * scale * 2) : -22 * scale * 2);

    self.viewControllerPlaceholderToBottomSpaceConstraint.constant = IS_WIDESCREEN ? 160 : 131;

    previewViewController.view.userInteractionEnabled = NO;

    [self.view setNeedsLayout];
}

解决方案

It seems like an iOS 8 bug to me. I had the same issue. My solution was to disable autolayout for preview and resort to autoresizingMask.

preview.translatesAutoresizingMaskIntoConstraints = YES;
preview.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
preview.frame = view.bounds;

But my preview view is a plain UIImageView. I have no clue how it would work with some complex autolayout-based preview view.

I have pretty similar setup as yours, I do use placeholder VC on top too, but it's built using autoresizingMask too, seemed like easier to center things vertically.

If you use any constraints inside of preview view and experience issues, then I would try to wrap preview in one more UIView and see if it works. [view (autoresizingMask, custom frame, scaled)] -> [view (autoresizingMask = Flexible W+H)] -> [Preview (Autolayout)]

这篇关于iOS的8 CGAffineTransformMakeScale +自动版式不再起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆