本文介绍了基于prefs显示/隐藏iphone UI元素 - 如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iPhone应用程式中有一个简单的表单。该表单通过IB和典型的布线(即我不是以编程方式创建此表单)布局和管理。

I've got a simple form in my iPhone app. The form is laid out and managed via IB and the typical wiring (i.e. I am not creating this form programmatically).

其中一个字段(及其相关标签)只有在设置了特定首选项时才会显示。

One of the fields (and its associated label) should be shown only if a particular preference is set.

I 可以将字段和标签的alpha设置为0,并在这种情况下禁用它们。问题是 此现在不可见字段的字段将保持在相同的位置,并且将存在大的空白区域。我的目标是让屏幕在任一状态下看起来都正常。

I could set the field and label's alpha to 0 and disable them in this case. The problem is that the fields below this now-invisible field would remain in the same place and there would be a big blank area. My goal is to have the screen look normal in either state.

有没有办法以编程方式删除(或添加)UI元素,让下面的元素向上或向下移动腾出空间?或者我应该考虑为第二种情况制作一个整体的其他NIB文件? (

Is there a way to programmatically remove (or add) UI elements and have those below shift up or down to make room? Or should I consider making a whole other NIB file for this second case? (and, if I do that, is there an easy way to share the common elements?)

推荐答案

到IBOutlet指针,例如

When every UI element is linked to a IBOutlet pointer, e.g.

@property (nonatomic, retain) IBOutlet UITextField *field_a;
@property (nonatomic, retain) IBOutlet UITextField *field_b;
@property (nonatomic, retain) IBOutlet UITextField *field_c;
// ...

您可以通过以下方式测试每个元素的可见性:

You can test each element's visibility by:

if (field_a.hidden) {
    // ...
} else {
    // ...
}

并移动它们:

CGPoint pt = field_a.center;
pt.y -= 60;
field_a.center = pt;

或由某些动画:

CGPoint position = field_a.center;
position.y -= 60;
[UIView beginAnimations:@"MoveUp" context:NULL];
[UIView setAnimationDuration:0.5];
field_a.center = position;
[UIView commitAnimations];

要隐藏元素:

field_a.hidden = YES;

显示元素:

field_a.hidden = NO;

这篇关于基于prefs显示/隐藏iphone UI元素 - 如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 16:42