繁体   English   中英

CGRect中的presentModalViewController

[英]presentModalViewController in CGRect

是否有可能以模态视图被限制在CGRect中包含的空间的方式呈现模态视图控制器?

如果没有,请解释如何复制两个视图之间的交叉解析模态视图转换。

谢谢。

要交叉解析为常规视图控制器,可以将其modalTransitionStyle设置为UIModalTransitionStyleCrossDissolve,然后以模态方式呈现它。

要在某些子视图对之间执行交叉消解(仅限于其框架CGRects),您可以使用此UIView方法:

+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion.

以下是您在代码中使用它的方法:

@interface ViewController ()

@property(strong,nonatomic) UIView *redView;
@property(strong,nonatomic) UIView *blueView;

@end

@implementation ViewController

@synthesize redView=_redView;
@synthesize blueView=_blueView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.redView = [[UIView alloc] initWithFrame:CGRectMake(40.0, 40.0, 240.0, 100.0)];
    self.redView.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.redView];

    self.blueView = [[UIView alloc] initWithFrame:CGRectMake(40.0, 40.0, 240.0, 100.0)];
    self.blueView.backgroundColor = [UIColor blueColor];
}

- (IBAction)crossDisolve:(id)sender {

    UIView *fromView = (self.redView.superview)? self.redView : self.blueView;
    UIView *toView = (fromView==self.redView)? self.blueView : self.redView;

    [UIView transitionFromView:fromView
                    toView:toView
                  duration:1.0
                   options:UIViewAnimationOptionTransitionCrossDissolve
                completion:^(BOOL finished) {NSLog(@"done!");}
 ];

 // now the fromView has been removed from the hierarchy and the toView has been added
 // please note that this code depends on ARC to release objects correctly

}

你的问题更难的部分是制作新的子视图“模态”的想法,我猜你的意思是只覆盖显示器的一部分,但只关注输入焦点。 最接近SDK的是UIAlertView。

你怎么用UIView动画:

UIView* view = [[UIView alloc] initWithFrame:CGRectMake(x,y,w,h)];
[view setAlpha:0];
[self.view addSubView:view];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[view setAlpha:1];
[UIView commitAnimations];

瞧! 它消失了! :)

暂无
暂无

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

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