iphone - CGRect 中的 presentModalViewController

标签 iphone objective-c ios modalviewcontroller presentmodalviewcontroller

是否有可能以模态视图被限制在 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/

相关文章:

iphone - 在Xcode中找不到-lstdc++的库

ios - 使用 Firebase 进行身份验证自动登录

iphone - 如何使用加速度计检测 iPhone 在太空中的运动?

ios - 选择 collectionView Cell 时根据条件执行两个不同的任务

iPhone Mobile Safari,最大并行 http 连接数是多少?

objective-c - 无法将文件内容从 .plist 文件获取到数组中

IOS 模拟器意外退出 Xcode 10.1

ios - 无法使用 'taskCreated' 类型的参数列表调用 '([String : String?])'

android - whatsapp 超链接 - 结合 whatsapp ://send? 与 intent://send/

iphone - 从 UItableview 中删除一行时崩溃