I have a view controller with a collection view on it. I dragged a UIView
onto the view controller as you can see below.
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
.
@property (strong, nonatomic) IBOutlet UIView *infoView;
Then I synthesised it: @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.
I have tried using CGRect
and CGPointMake
but it just doesn't move! Can someone show me the exact code I can use to move the UIView
by my desired amount within the ViewDidLoad
method?
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
. Try moving your subview in
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.