简体   繁体   English

从其superView中移除UIView并将其框架扩展到全屏

[英]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. 我有一个对象,它是UIView的子类,可以作为子视图添加到视图层次结构中。 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. 我希望能够从其superView中删除UIView并将其作为主窗口的子视图添加,然后扩展到全屏。

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? 其次,对象是否有一种轻松的方法来获取指向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. 否则动画将不流畅。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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