添加三个子视图后,工具栏消失

时间:2013-03-02 00:19:24

标签: ios xcode uiview uiimageview uicollectionview

您好我正在尝试在同一屏幕上将项目从集合视图添加到uiview。当用户点击我发现的单元格并将其放到下面的mycreationview时(我还希望用户移动这些添加的uiimages)。我在顶部有一个工具栏可以返回等等。现在,当我点击单元格3次时,会添加3个图像进行查看,但随后工具栏消失,其后面的按钮隐藏在顶部/左侧,只有四分之一可见,怎么能我调试了吗?

    myCollectionViewCell* cell=(myCollectionViewCell* ) [self.myCollectionView cellForItemAtIndexPath:index];
    UIImageView *iv = [[UIImageView alloc]initWithImage:cell.myCellImageView.image];
    iv.contentMode = UIViewContentModeScaleAspectFill;
    NSLayoutConstraint * constraint1 = [NSLayoutConstraint constraintWithItem:iv attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.myCreationView attribute:NSLayoutAttributeWidth multiplier:0.4f constant:0];
    NSLayoutConstraint * constraint2 = [NSLayoutConstraint constraintWithItem:iv attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.myCreationView attribute:NSLayoutAttributeHeight multiplier:0.4f constant:0];
    NSLayoutConstraint * constraint3 = [NSLayoutConstraint constraintWithItem:iv attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.myCreationView attribute:NSLayoutAttributeLeft multiplier:0 constant:10];
    NSLayoutConstraint * constraint4 = [NSLayoutConstraint constraintWithItem:iv attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.myCreationView attribute:NSLayoutAttributeTop multiplier:0 constant:10];

    [iv setTranslatesAutoresizingMaskIntoConstraints:NO];
    iv.autoresizesSubviews=YES;
    iv.userInteractionEnabled=YES;
    [self.myCreationView addSubview:iv];
    [self.myCreationView addConstraint:constraint1];
    [self.myCreationView addConstraint:constraint2];
    [self.myCreationView addConstraint:constraint3];
    [self.myCreationView addConstraint:constraint4];

myCollectionViewCell* cell=(myCollectionViewCell* ) [self.myCollectionView cellForItemAtIndexPath:index]; UIImageView *iv = [[UIImageView alloc]initWithImage:cell.myCellImageView.image]; iv.contentMode = UIViewContentModeScaleAspectFill; NSLayoutConstraint * constraint1 = [NSLayoutConstraint constraintWithItem:iv attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.myCreationView attribute:NSLayoutAttributeWidth multiplier:0.4f constant:0]; NSLayoutConstraint * constraint2 = [NSLayoutConstraint constraintWithItem:iv attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.myCreationView attribute:NSLayoutAttributeHeight multiplier:0.4f constant:0]; NSLayoutConstraint * constraint3 = [NSLayoutConstraint constraintWithItem:iv attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.myCreationView attribute:NSLayoutAttributeLeft multiplier:0 constant:10]; NSLayoutConstraint * constraint4 = [NSLayoutConstraint constraintWithItem:iv attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.myCreationView attribute:NSLayoutAttributeTop multiplier:0 constant:10]; [iv setTranslatesAutoresizingMaskIntoConstraints:NO]; iv.autoresizesSubviews=YES; iv.userInteractionEnabled=YES; [self.myCreationView addSubview:iv]; [self.myCreationView addConstraint:constraint1]; [self.myCreationView addConstraint:constraint2]; [self.myCreationView addConstraint:constraint3]; [self.myCreationView addConstraint:constraint4];

1 个答案:

答案 0 :(得分:0)

回答我的问题。我让视图变小了一点,而不是触摸工具栏,问题就消失了。所以我猜如果他们互相接触会产生约束。