2013-02-16 105 views
2

我有UiTableView within UiView。我想將corner radius & shadow設置爲UIView。 我使用此代碼給shadow with corner和它的工作正常。UIView定向陰影問題

myView.backgroundColor = [UIColor clearColor]; 
[myView.layer setCornerRadius:10.0f]; 
[myView.layer setBorderColor:[UIColor lightGrayColor].CGColor]; 
[myView.layer setBorderWidth:1.0f]; 
[myView.layer setShadowColor:[UIColor blackColor].CGColor]; 
[myView.layer setShadowOpacity:0.8]; 
[myView.layer setShadowRadius:3.0]; 
[myView.layer setShadowOffset:CGSizeMake(2.0, 2.0)]; 

// below line is for smooth scrolling 
[myView.layer setShadowPath:[UIBezierPath bezierPathWithRect:myView.bounds].CGPath];` 

一切工作正常與Portrait mode。我的應用程序支持Orientation,我們使用的是Autoresizing property。當我改變方向Shadow is displaying according to frame of Portrait mode。這對於這兩種定位如何管理。

任何想法如何根據Orientation OR bound來更改setShadowPath

回答

0

我有一個發現我自己的解決方案。我有一個創建的方法- (void) viewWithEffects: (UIView*) myView {// copy the shadow code from the question}。現在我把這個方法叫做- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{}

所以當方向改變didRotateFromInterfaceOrientation打電話,它會給Corner with Shadow effects.影子會根據你的設置Autoresize你的看法。如果你的應用程序不支持這兩種取向比不需要這樣做。請致電viewdidload or viewwillAppear。我希望這會有所幫助。

0

iOS6的旋轉 試試這個代碼,讓我知道,如果它的工作對你

- (BOOL)shouldAutorotate 
{ 
    if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) 
    { 
    self.view.backgroundColor = [UIColor redColor]; 
    } 
else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) 
    { 
    self.view.backgroundColor = [UIColor blackColor]; 
    } 

return YES; 
}