【问题标题】:UIView shadow issue with orientationUIView 阴影问题与方向
【发布时间】:2013-02-16 07:58:59
【问题描述】:

我有UiTableView within UiView。我想将corner radius & shadow 设置为UIView。 我正在使用此代码提供 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。这如何管理两个方向。

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

【问题讨论】:

    标签: uiview orientation layer uibezierpath dropshadow


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我找到了自己的解决方案。我有一个创建的方法- (void) viewWithEffects: (UIView*) myView {// copy the shadow code from the question}。现在我将此方法称为- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{}

      因此,当方向更改didRotateFromInterfaceOrientation 调用时,它会给Corner with Shadow effects. 阴影将根据Autoresize 您的视图设置到您的视图。如果您的应用程序不支持两个方向,则不需要这样做。只需拨打viewdidload or viewwillAppear 即可。我希望它会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-07-09
        • 1970-01-01
        • 2014-07-08
        • 2011-11-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-06
        相关资源
        最近更新 更多