[英]How can I move my UIView in xcode?
I have a view controller with a collection view on it. 我有一个视图控制器,上面有一个集合视图。 I dragged a
UIView
onto the view controller as you can see below. 我将
UIView
拖到视图控制器上,如下所示。
I attached a label, also note the white border is from the collection cell. 我贴了标签,还注意白色边框来自收集单元。
Then, In the CollectionViewController
class that is attached to the actual view controller, (the UIView
doesn't have a custom class) I created an outlet and attached it to the UIView
. 然后,在附加到实际视图控制器的
CollectionViewController
类中( UIView
没有自定义类),我创建了一个插座并将其附加到UIView
。
@property (strong, nonatomic) IBOutlet UIView *infoView;
Then I synthesised it: @synthesize infoView;
然后我合成了它:
@synthesize infoView;
Now, in the ViewDidLoad
method, I want to be able to move the view down out of the screen so its not visible. 现在,在
ViewDidLoad
方法中,我希望能够将视图向下移出屏幕,从而使其不可见。
I have tried using CGRect
and CGPointMake
but it just doesn't move! 我已经尝试过使用
CGRect
和CGPointMake
但是它不会移动! Can someone show me the exact code I can use to move the UIView
by my desired amount within the ViewDidLoad
method? 有人可以告诉我在
ViewDidLoad
方法中可以用来按所需量移动UIView
的确切代码吗?
First remove the view from superview 首先从超级视图中删除视图
[infoview removeFromSuperView];
After that you can adjust the new frame of view 之后,您可以调整新的视野
infoview.frame = CGRectMake(x,y,width,height);
Now add the view again to superview 现在再次将视图添加到超级视图
[self.view addSubVeiw:infoView];
To animate a view to a new frame, use the following code 要将视图动画化为新框架,请使用以下代码
infoView.frame = CGRectMake(x,y,width,height);//initial frame
[UIView animateWithDuration:0.25 animations:^{
infoView.frame = CGRectMake(x,y,width,height);//new frame
}];
Subviews are not properly set yet in viewDidLoad
. 尚未在
viewDidLoad
正确设置子视图。 Try moving your subview in 尝试将子视图移入
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.