我设置了一个UIImageView来接受点击手势,点击按钮将隐藏起来,并在相同的位置显示一个UIActivityIndicatorView。逻辑很简单。但我有两个问题:
[fb setTranslatesAutoresizingMaskIntoConstraints:NO];或[loading setTranslatesAutoresizingMaskIntoConstraints:NO];来避免约束冲突。为了安全起见,我加了两个。UIImageView和UIActivityIndicatorView似乎都有自己的内置约束:
"","",";8d68700.midX == + 18.5>",“”。[fb setTranslatesAutoresizingMaskIntoConstraints:NO];或[loading setTranslatesAutoresizingMaskIntoConstraints:NO];这一行进行评论。否则,UITapGestureRecognizer不再工作了,为什么?代码:
- (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];
}发布于 2014-02-05 10:28:13
您需要调用setTranslatesAutoresizingMaskIntoConstraints:NO,因为自动调整掩码被转换为与自动收费系统冲突的约束。您通常不能使用自动调整掩码约束将自动布局约束添加到视图中,否则将进入不兼容的约束。
在您的情况下,主要问题是无法确定这些问题的宽度和高度。您还需要添加宽度和高度约束。如果自动布局系统无法计算,则无法使用中心约束来确定布局。
https://stackoverflow.com/questions/21574350
复制相似问题