首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Autolayout停止UITapGestureRecognizer?

Autolayout停止UITapGestureRecognizer?
EN

Stack Overflow用户
提问于 2014-02-05 10:17:05
回答 1查看 941关注 0票数 2

我设置了一个UIImageView来接受点击手势,点击按钮将隐藏起来,并在相同的位置显示一个UIActivityIndicatorView。逻辑很简单。但我有两个问题:

  • 我需要添加[fb setTranslatesAutoresizingMaskIntoConstraints:NO];[loading setTranslatesAutoresizingMaskIntoConstraints:NO];来避免约束冲突。为了安全起见,我加了两个。UIImageView和UIActivityIndicatorView似乎都有自己的内置约束: "","",";8d68700.midX == + 18.5>",“”。
  • 我必须对[fb setTranslatesAutoresizingMaskIntoConstraints:NO];[loading setTranslatesAutoresizingMaskIntoConstraints:NO];这一行进行评论。否则,UITapGestureRecognizer不再工作了,为什么?

代码:

代码语言:javascript
复制
- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view.

    // setup the loading activity indicator;
    loading = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [self.view addSubview:loading];
    loading.hidden = YES;

    // setup the fb button
    fb = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"facebook.png"]];
    fb.userInteractionEnabled = YES;

    UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] init];
    [tap addTarget:self action:@selector(login:)];
    [fb addGestureRecognizer:tap];

    [self.view addSubview:fb];
    fb.hidden = YES;

    NSLayoutConstraint *c;
    c = [NSLayoutConstraint constraintWithItem:fb
                                     attribute:NSLayoutAttributeCenterX
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.view
                                     attribute:NSLayoutAttributeCenterX
                                    multiplier:1
                                      constant:0];
    [self.view addConstraint:c];
    c = [NSLayoutConstraint constraintWithItem:fb
                                     attribute:NSLayoutAttributeCenterY
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.view
                                     attribute:NSLayoutAttributeCenterY
                                    multiplier:1
                                      constant:0];
    [self.view addConstraint:c];

    c = [NSLayoutConstraint constraintWithItem:loading
                                     attribute:NSLayoutAttributeCenterX
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.view
                                     attribute:NSLayoutAttributeCenterX
                                    multiplier:1
                                      constant:0];
    [self.view addConstraint:c];
    c = [NSLayoutConstraint constraintWithItem:loading
                                     attribute:NSLayoutAttributeCenterY
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.view
                                     attribute:NSLayoutAttributeCenterY
                                    multiplier:1
                                      constant:0];
    [self.view addConstraint:c];

    [fb setTranslatesAutoresizingMaskIntoConstraints:NO];
    [loading setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self.view setTranslatesAutoresizingMaskIntoConstraints:NO];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-05 10:28:13

您需要调用setTranslatesAutoresizingMaskIntoConstraints:NO,因为自动调整掩码被转换为与自动收费系统冲突的约束。您通常不能使用自动调整掩码约束将自动布局约束添加到视图中,否则将进入不兼容的约束。

在您的情况下,主要问题是无法确定这些问题的宽度和高度。您还需要添加宽度和高度约束。如果自动布局系统无法计算,则无法使用中心约束来确定布局。

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

https://stackoverflow.com/questions/21574350

复制
相关文章

相似问题

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