UIView有方向的阴影问题
我在UiView中有UIView有方向的阴影问题,uiview,orientation,layer,uibezierpath,dropshadow,Uiview,Orientation,Layer,Uibezierpath,Dropshadow,我在UiView中有UiTableView。我想将角半径和阴影设置为ui视图。 我用这段代码给出了带角的阴影,效果很好 myView.backgroundColor = [UIColor clearColor]; [myView.layer setCornerRadius:10.0f]; [myView.layer setBorderColor:[UIColor lightGrayColor].CGColor]; [myView.layer setBorderWidth:1.0f]; [myVi
UiTableView
。我想将角半径和阴影
设置为ui视图
。
我用这段代码给出了带角的阴影
,效果很好
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];`
在纵向模式下一切正常。我的应用程序同时支持定向
,我们正在使用自动调整大小属性
来实现这一点。当我改变方向时,阴影根据纵向模式的帧显示。如何管理这两个方向
您知道如何根据方向或边界更改设置阴影路径吗?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;
}
我找到了自己的解决办法。我创建了一个方法-(void)viewWithEffects:(UIView*)myView{//copy the shadow code from the question}
。现在我将这个方法从InterfaceOrientation{}
调用为-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)
因此,当方向更改时,didRotateFromInterfaceOrientation
调用,它将为角提供阴影效果。
Shadow将根据自动调整视图大小来设置视图。如果您的应用程序不支持这两种方向,则不需要执行此操作。只需在viewdidload上调用一个,否则viewdidload将出现。我希望这会有帮助