0

I have UIView, I want to add it a view on that view but so it be half of the size of the original View.

I tried :

[appDelegate.viewController presentModalViewController:testViewController animated:NO];

but itws on all the screen.

tried:

self.window.frame= CGRectMake(50, 50, 30, 30);
self.frame= CGRectMake(50, 50, 30, 30)

I saw there is methods like presentPopupViewController but they work on UIViewcontroller. any ideas to start it on half of the screen?

4

3 回答 3

0

该消息presentModalViewController:animated:将以模态方式呈现视图,始终占据整个屏幕。它不会将视图添加到您当前的视图中。

为此,请使用UIView's message addSubview:。您可以根据需要调整子视图的大小。

于 2012-08-29T10:04:13.993 回答
0

使用 presentModalViewController:animated: 无法调整大小。

要产生像 presentModalViewController:animated: 这样的效果,请使用 CATransition:

 CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionMoveIn];
[animation setSubtype:kCATransitionFromBottom];
[animation setDuration:0.50];
[animation setTimingFunction:
 [CAMediaTimingFunction functionWithName:
  kCAMediaTimingFunctionEaseInEaseOut]];
[self.view.layer addAnimation:animation forKey:kCATransition];

现在在 self.view 中添加视图,如下所示:

[self.view addSubView:testViewController.view];
[testViewController.view setFrame:CGRectMake((self.view.frame.size.width/4),(self.view.frame.size.height/4),(self.view.frame.size.width*3/4),(self.view.frame.size.height*3/4))];
于 2012-08-29T10:22:48.437 回答
0

假设您有两个视图,一个是mainview第二个是childview

在主视图上添加子视图

 [mainview addSubview:childview];

从主视图中删除子视图

 [childview removeFromSuperview];

但是如果你想要一些动画而不是你必须为此添加一些额外的代码。

于 2012-08-29T10:25:50.230 回答