2

我有UiTableView within UiView。我想设置corner radius & shadowUIView. 我正在使用此代码来提供shadow with corner并且工作正常。

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。这如何管理两个方向。

知道如何setShadowPath根据 Orientation OR bound 进行更改吗?

4

2 回答 2

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。我希望它会有所帮助。

于 2013-02-16T12:47:36.143 回答
0

iOS6 Rotation 试试这个代码,让我知道它是否适合你

 - (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;
} 
于 2013-02-16T10:37:09.300 回答