UIView shadow issue with orientation

我们两清 提交于 2019-12-12 10:05:30

问题


I have UiTableView within UiView. I want to set corner radius & shadow to UIView. I am using this code to give shadow with cornerand its working fine.

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];`

everything working fine with Portrait mode. My app is supported both Orientation and we are using Autoresizing property fot that. When i change the orientation Shadow is displaying according to frame of Portrait mode. How can this manage for both Orientation.

Any idea how to change setShadowPath according to Orientation OR bound ?


回答1:


iOS6 Rotation Try this code and let me know if it worked for you

 - (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;
} 



回答2:


I have a found the solution of my own. i have a created one method - (void) viewWithEffects: (UIView*) myView {// copy the shadow code from the question}. Now i called this method to - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{} .

So when orientation change didRotateFromInterfaceOrientation call and it will give the Corner with Shadow effects. Shadow will set to your view according to Autoresize your view. if your app not supported for both orientation than dont need to do this. Just call one on viewdidload or viewwillAppear. i hope it will help .



来源:https://stackoverflow.com/questions/14908255/uiview-shadow-issue-with-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!