我一直在用UIImageView設置約束後,用手機攝像頭的圖像初始化它有一些麻煩。如果我運行代碼如下:UIImageView和自動佈局
UITextView *textView = self.textView;
UIImageView *imageView = [[UIImageView alloc] initWithImage:self.item.accessoryImage];
UILabel *label = self.textLabel;
self.accessoryImageView = imageView;
[self.contentView addSubview:self.accessoryImageView];
[self.contentView removeConstraints:self.contentView.constraints];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[textView]-2-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(textView, label)]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-100-[textView]-2-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(textView, label)]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[imageView(==100)]-10-[textView]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(imageView,textView)]];
自動佈局決定打破ImageView的(== 100)約束和尺寸而不是所述的ImageView幀爲2000+點寬,這是圖像的尺寸相同。有沒有人知道解決這種情況的方法?
'imageView(== 100)'代表什麼?如果你想設置一個固定寬度,爲什麼不使用'imageView(100)'? '== view'用於設置兩個視圖之間的維度相等,例如'[按鈕1(== BUTTON2)]'。也許autolayout系統將'100'視爲標識符? – vokilam