简体   繁体   中英

Removing a UIView from its superView and expanding its frame to full screen

I have an object that is a subclass of UIView that can be added to a view hierarchy as a subView. I want to be able to remove the UIView from its superView and add it as a subView of the main window and then expand to full screen.

Something along the lines of:

// Remove from superView and add to mainWindow
[self retain];
[self removeFromSuperView];
[mainWindow addSubView:self];

// Animate to full screen
[UIView beginAnimations:@"expandToFullScreen" context:nil];
[UIView setAnimationDuration:1.0];
self.frame = [[UIScreen mainScreen] applicationFrame];
[UIView commitAnimations];

[self release];

Firstly am I on the right lines? Secondly, is there an easily way for the object to get a pointer to the mainWindow?

Thanks

Dave

您可以使用视图的窗口属性

self.window

Looks good. But you might want to convert the view's frame from its superview coordinate system to the window's coordinate system, before beginning the animation. Otherwise the animation will not be smooth.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM