2016-09-30 2 views
0

IBにレイアウトロジックの大部分を持つプロジェクトがあります。私はviewDidAppearでそれを置くように、動的に更新したい位置のいくつか:アクションが起動されるたびにIOSビューがデフォルトのIBレイアウトに更新されます

- (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]; 
} 
+0

自動レイアウトを使用していますか? – random

+0

@randomはい私は –

+0

レイアウトをリセットするこれらの「アクション」を実行するときに実行されているコードを表示する必要があります。 – Zolnoor

答えて

1

あなたは制約はなく、あなたのオブジェクトの実際のフレームを更新する必要があります。したがって、ボタンフレームyの制約をIBOutletとして追加すると、簡単に編集できます。 https://autolayoutconstraints.com/

+0

現在のところ、私はそれらのボタンには制約がありません。そのビューの他のコンポーネント....これらのボタンにも制約を追加する必要がありますか、フレームで行う方法はありますか? –

+0

はい、またはプログラムでそれらを作成し、ビューがそれをサブビューした後に追加します。 – random

+0

ああ、それは痛みです....また、プログラムで設定したサイズがIBのものに戻っていることに気付きました。それを防ぐ方法はありますか? –

1

私はそれが私のポジショニングをいじりされた自動レイアウトであることが判明:

はここで自動レイアウトの制約と遊ぶのが本当にクールなツールです。 AutoLayoutが自分の設定を乱してしまうのを防ぐためにtranslatesAutoresizingMaskIntoConstraintsをtrueに設定できました:

// 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; 
} 
関連する問題