gpt4 book ai didi

iphone - CGRect 中的 presentModalViewController

转载 作者:行者123 更新时间:2023-11-28 23:01:29 25 4
gpt4 key购买 nike

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

如果不是,请解释如何在两个 View 之间复制交叉溶解模态视图转换。

谢谢。

最佳答案

要交叉溶解到常规 View Controller ,您可以将它的 modalTransitionStyle 设置为 UIModalTransitionStyleCrossDissolve,然后以模态方式呈现它。

要在某些 subview (限于它们的框架 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

}

你的问题中较难的部分是使新的 subview 成为“模式”的想法,我猜你的意思是它只覆盖显示的一部分,但只接受输入焦点。 SDK 中最接近它的是 UIAlertView。

关于iphone - CGRect 中的 presentModalViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9958833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com