0

是否有可能以模態視圖限制在CGRect中包含的空間的方式呈現模態視圖控制器?presentModalViewController in CGRect

如果不是,請解釋如何複製兩個視圖之間的交叉混合模式視圖轉換。

謝謝。

回答

0

你怎麼樣只是使用的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]; 

瞧!它淡入! :)

2

要交叉分解爲常規視圖控制器,可以將其設置爲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。

+0

非常感謝。你能舉一個簡單的例子來說明它對子視圖的使用嗎? – 2012-03-31 19:42:28

+0

你的意思是UIView過渡?當然,會掀起一些未經過超級測試並編輯我的答案。 – danh 2012-03-31 20:25:55

+0

再次感謝。對於我的具體情況,由於其簡單性,我發現上面的答案更有幫助。我希望我可以標記兩個答案是正確的,但我一定會馬上對此表示讚賞。再次感謝。 – 2012-04-01 16:34:20