UIView定向阴影问题
问题描述:
我有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
?
答
我有一个发现我自己的解决方案。我有一个创建的方法- (void) viewWithEffects: (UIView*) myView {// copy the shadow code from the question}
。现在我把这个方法叫做- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{}
。
所以当方向改变didRotateFromInterfaceOrientation
打电话,它会给Corner with Shadow effects.
影子会根据你的设置Autoresize
你的看法。如果你的应用程序不支持这两种取向比不需要这样做。请致电viewdidload or viewwillAppear
。我希望这会有所帮助。
答
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;
}