2013-11-15 25 views
3

我有一個共享頁面的簡短介紹,其中包括點擊共享按鈕和模態視圖在頂部顯示一些共享功能。模態視圖透明背景 - 停止低層隱藏?

我的問題是,我希望模態視圖的背景是半透明的,因此顯示下方的視圖。我已經設置了模態圖層的背景屬性,當模態出現時,下面的圖層可以簡單地看到 - 並且看起來完全符合我的要求 - 但是一旦封面過渡完成,背景視圖就會隱藏 - 是否有任何方法這個?

(使用IOS7的方式)

乾杯

更新 - @Tommaso Resti慷慨地幫助我嘗試和推測這個問題了 - 解釋什麼,我這樣做的遠 - 我的主故事板包含一個未鏈接的uiview,標識符爲'ShareScreenView' - 我想在單擊按鈕時將其添加到我的mainView中作爲透明模式。我已鏈接按鈕作爲IBAction爲和增加了以下我的方法 -

- (IBAction)shareBtn:(id)sender { 


    NSLog(@"clicked"); 



    /* Create your view off the screen (bottom) */ 

    /* NEW EDIT */ 
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" 
                 bundle: nil]; 
    UIViewController *myModalController = [mainStoryboard instantiateViewControllerWithIdentifier:@"ShareScreenView"]; 

    [myModalController.view setFrame:CGRectMake(0, 568, 320, 568)]; 
// [myModalController.view setFrame: CGRectMake(0, [[UIScreen mainScreen].bounds.size.height], [[UIScreen mainScreen].bounds.size.width], [[UIScreen mainScreen].bounds.size.height])]; 


/* Animate it from the bottom */ 
[UIView animateWithDuration:.5 animations:^{ 
    CGAffineTransform move = CGAffineTransformMakeTranslation(0, -[UIScreen mainScreen].bounds.size.height); 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
    myModalController.view.transform = move; /* UPDATED HERE */ 
    NSLog(@"Atrying"); 
} completion:^(BOOL finished) { 
    NSLog(@"Adid try"); 
    if(finished) { 
     NSLog(@"Animation completed"); 
    } 
}]; 

} 

,但我得到就行了一個錯誤 -

[myModalController.view SETFRAME:CGRectMake(0,[UIScreen mainScreen ] .bounds.size.height],[[UIScreen mainScreen] .bounds.size.width],[[UIScreen mainScreen] .bounds.size.height])];

其簡單地陳述「預期標識符」與高度的箭頭指示(見下文截屏)

enter image description here

所以我嘗試添加屬性如下 -

[myModalController.view setFrame:CGRectMake(0, 568, 320, 568)]; 

現在有沒有錯誤 - 但沒有任何反應,也沒有錯誤..

回答

3

我建議使用你自己的方法:

是這樣的:

/* Create your view off the screen (bottom) */ 

/* NEW EDIT */ 
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" 
                bundle: nil]; 
UIViewController *myModalController = [mainStoryboard instantiateViewControllerWithIdentifier:@"MyModalController"]; 
[myModalController.view setFrame: CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)]; 
[self.view addSubview: myModalController.view]; /* UPDATED HERE! */ 


/* Animate it from the bottom */ 
[UIView animateWithDuration:.5 animations:^{ 
    CGAffineTransform move = CGAffineTransformMakeTranslation(0, -[UIScreen mainScreen].bounds.size.height); 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
    myModalController.view.transform = move; /* UPDATED HERE */ 
} completion:^(BOOL finished) { 
    if(finished) { 
     NSLog(@"Animation completed"); 
    } 
}]; 

比這個動畫刪除:

/* Reset animation */ 
[UIView animateWithDuration:.5 animations:^{ 
    CGAffineTransform reset = CGAffineTransformIdentity; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
    myModalController.view.transform = reset; /* UPDATED HERE */ 
} completion:^(BOOL finished) { 
    if(finished) { 
     NSLog(@"Reset completed"); 
     [myModalController.view removeFromSuperview]; 
    } 
}]; 

--- EDITED --- 對不起,我忘了myViewController後添加 「.view」。 我從不嘗試我的代碼...我的錯;)

該示例已更新!

+0

涼爽的歡呼聲 - 我可以用這個方法用故事板?我從來沒有用過Nibs! – Dancer

+0

當然!使用 UIViewController * myModalController = [storyboard instantiateViewControllerWithIdentifier:@「MyModalController」];而不是UIViewController myModalController = [[UIViewController allor] initWithNibName:@「MyModalController」bundle:[NSBundle mainBundle]]; –

+0

很酷的歡呼 - 一個問題 - 我得到一個錯誤,指出'在這一行UIViewController找不到屬性轉換 - myModalController.transform = move; – Dancer

0

您可以創建一個視圖,從底部滑入,然後使視圖變爲半透明。

0

您可以使用View容器來創建自己的ModalViewController並做動畫就像@Tommaso Resti說