0
나는 그렇게 내가이 선택 될 때 알아야 할 UIControl을 추가 할 수있는 UIImageView를 서브 클래 싱하기 위해 노력하고있어 추가 : 내가 UIControl를 만들기 위해 제약 조건을 추가하려고서브 클래 싱있는 UIImageView와 UIControl
-(id)initWithSize:(CGSize)size OffImage:(UIImage *)offImage onImage:(UIImage *)onImage
{
if (self) {
[self setTranslatesAutoresizingMaskIntoConstraints:NO];
self.userInteractionEnabled = TRUE;
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[self(80)]"
options:0
metrics:@{@"WIDTH" : [NSNumber numberWithFloat:size.width]}
views:NSDictionaryOfVariableBindings(self)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[self(90)]"
options:0
metrics:@{@"HEIGHT" : [NSNumber numberWithFloat:size.height]}
views:NSDictionaryOfVariableBindings(self)]];
self.offImage = offImage;
self.onImage = onImage;
self.selected = FALSE;
UIControl *control = [[UIControl alloc] init];
[control setTranslatesAutoresizingMaskIntoConstraints:NO];
self.control = control;
[self addSubview:control];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[control]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(control)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[control]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(control)]];
}
return self;
}
서브 클래 싱 된 UIImageView에 같은 크기, 내가 그 self.control은 수퍼없는 말을 오류가 : 나는있는 UIImageView를 만들어 일의 동일한 유형을 할 경우
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse constraint format:
Unable to interpret '|' character, because the related view doesn't have a superview
H:|[control]|
^'
은 다음 UIControl과 [imageView addsubview:control]
을 만들을, 그것을 잘 작동합니다. init
메서드에 동일한 코드를 추가하려고하면 충돌이 발생하는 이유는 무엇입니까?
바, 감사합니다! 'self = [super init]'을 잊어 버렸습니다. 이제 나는 어리 석다. – Padin215