簡體   English   中英

每當觸發操作時,IOS視圖就會更新為默認IB布局

[英]IOS view updates to default IB layout whenever an action is fired

我有一個項目,該項目的大部分布局邏輯都在IB中。 我想動態更新一些定位,因此將其放在viewDidAppear中:

- (void)viewDidAppear:(BOOL)animated{
// Fill array of button tools
buttonArray = [[NSArray alloc] initWithObjects:
               self.filterButton, self.bulgeButton, self.stickerButton, self.textButton, self.drawButton, self.invertedBulgeButton, nil];

// Position button tools
int const X_POSITION = 175; // The x position of the tool buttons
int yPosition = 0; // The x position of the tool buttons
CGRect frame = CGRectMake(X_POSITION, yPosition, 100, 100); // The position and size of the tool buttons

// Loop through buttons and set properties
for (UIButton *button in buttonArray) {
    frame.origin.y = yPosition;
    button.frame = frame;
    yPosition += 75;
    button.hidden = false;
}
}

我的問題是,每當我按下另一個按鈕時,我在viewDidAppear中應用的所有格式都將被撤消,並且按鈕的位置將更改為IB中的位置。 如何防止我的按鈕移動到IB中設置的位置?

編輯:這是一些將導致位置更改的代碼:

// Undoes most recent edit to photo
- (IBAction)undoButtonPress:(id)sender {
    [self undoImage];
}

- (void)undoImage {
    // TODO:  Add all the other current actions.... none of them work because they need to be checked for here
    // Remove tools for the current action
    self.imageSticker.image = nil;
    [self refreshImageText];

    currentAction = NONE;
    self.mainImage.image = [_images pop];

}
// after done editing the text, this resets the text fields so you can create a second text
- (void) refreshImageText{
    self.hiddenTextField.text = @"";
    self.imageText.text = @"";

    self.imageText.transform = CGAffineTransformMakeRotation(0);
    [self.imageText setCenter:self.view.center];
}

您需要更新約束,而不是對象的實際框架。 因此,如果將按鈕框y約束添加為IBOutlet ,則可以輕松對其進行編輯。

這是一個使用自動布局約束的非常酷的工具: https ://autolayoutconstraints.com/

我發現是AutoLayout弄亂了我的位置。 我能夠將translatesAutoresizingMaskIntoConstraints設置為true,以防止AutoLayout干擾我的設置:

// Loop through buttons and set properties
for (UIButton *button in buttonArray) {
    frame.origin.y = yPosition;
    button.frame = frame;
    yPosition += 75;
    button.hidden = false;
    button.translatesAutoresizingMaskIntoConstraints = YES;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM