【发布时间】:2012-03-31 19:08:59
【问题描述】:
是否可以以将模态视图限制在 CGRect 中包含的空间的方式呈现模态视图控制器?
如果不是,请说明如何在两个视图之间复制交叉溶解模态视图转换。
谢谢。
【问题讨论】:
标签: iphone objective-c ios modalviewcontroller presentmodalviewcontroller
是否可以以将模态视图限制在 CGRect 中包含的空间的方式呈现模态视图控制器?
如果不是,请说明如何在两个视图之间复制交叉溶解模态视图转换。
谢谢。
【问题讨论】:
标签: iphone objective-c ios modalviewcontroller presentmodalviewcontroller
要交叉溶解到常规视图控制器,您可以将其 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];
瞧!它消失了! :)
【讨论】: