简体   繁体   English

如何在xcode中移动UIView?

[英]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! 我已经尝试过使用CGRectCGPointMake但是它不会移动! 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.

相关问题 平移时如何将 UIView 移动到另一个父级? - How can I move a UIView to another parent while panning? 我如何为UIView绘制阴影 - How i can draw the shadow for my uiview 我无法使用鼠标移动在XCode中选择我的代码 - I can't use mouse move to select my code in XCode 如何在collectionView的顶部使用UIView,以便在滚动单元格时UIView不应移动? - How can use UIView on top of collectionView, so that when i scroll cells, UIView should not move? 如何将 UIView 底部锚点向右移动到底部导航栏? - How do I move my UIView bottom anchor right about my bottom navigation bar? 如何将UIView移动到“底部”以便显示下一个UIView? - How do I move the UIView to the “bottom” so that the next UIView displays? 如何在Xcode 4中使用git移动文件和文件夹? - How can I move files & folders using git in Xcode 4? 创建视图控制器时,我没有检查“Targeted for iPad”选项。 如何使用XCode 4.2修复我的UIView作为iPad设备的目标? - I didn't check the Targeted for iPad option when creating a View Controller. How can I fix my UIView to be targeted for iPad devices using XCode 4.2? 如何在UIView中放置小图像 - How can I place a small image in my UIView 如何将我的视图之一与 UIView class 连接? - How can I connect one of my View with UIView class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM