2

我有两个 UIViewControllers A 和 B,它们作为子视图添加到 AppDelegate 中,B 在 A 之上。

当点击 B 上的 UIButton 时,B 会向左滑动,代码如下:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(slideOutFinished)];
simonSaysView.view.frame = CGRectMake(40-BView.view.frame.size.width, BView.view.frame.origin.y, BView.view.frame.size.width, BView.view.frame.size.height);
[UIView commitAnimations];

在右边缘我想要一个 20px 的阴影,但我不能使用阴影属性,BView.view.layer.shadow....因为它只有 3.2/4.0+。而且动画的表现很糟糕,幻灯片非常滞后(没有阴影的流畅)。

我正在考虑使用自定义 UIView 并在 drawRect 中做一些魔术,但这是可能的还是我只能在视图的范围内绘制?

希望你们中的一些人和女孩可以帮助我。

干杯 objneodude

4

2 回答 2

3

用下面的代码解决

// Add drop shadow to the view.
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = CGRectMake(self.view.frame.size.width, 0, 30, self.view.frame.size.height);
gradientLayer.colors = [NSArray arrayWithObjects:
                        (id)[UIColor blackColor].CGColor,
                        (id)[UIColor clearColor].CGColor,
                        nil];
gradientLayer.startPoint = CGPointMake(-2, 0.5);
gradientLayer.endPoint = CGPointMake(1, 0.5);   
[self.view.layer addSublayer:gradientLayer];
于 2010-10-26T12:39:49.847 回答
0

我遇到了同样的问题,在尝试了各种想法之后,我只是在 UIView 后面添加了一个阴影颜色(灰色)的子视图,我需要一个阴影,请参见代码:(包括 >3.2.x/4.x 的代码为好。

    /*Shaded/rounded borders on subviews*/
self.viewOne.layer.cornerRadius = 10;

self.viewOne.layer.borderColor = [UIColor darkGrayColor].CGColor;
self.viewOne.layer.borderWidth = 0.8;

self.viewTwo.layer.cornerRadius = 10;
self.viewTwo.layer.borderColor = [UIColor darkGrayColor].CGColor;
self.viewTwo.layer.borderWidth = 0.8;

self.viewThree.layer.cornerRadius = 10;
self.viewThree.layer.borderColor = [UIColor darkGrayColor].CGColor;
self.viewThree.layer.borderWidth = 0.8;

if (SYSTEM_VERSION_LESS_THAN(@"3.2")) {
    self.shadowOne.layer.cornerRadius = 10;
    self.shadowTwo.layer.cornerRadius = 10;
    self.shadowThree.layer.cornerRadius = 10;
}
else{
    //Use QuartzCore to make shadows etc.
    self.viewOne.layer.shadowColor = [[UIColor grayColor] CGColor];
    self.viewOne.layer.shadowOffset = CGSizeMake(2, 2);
    self.viewOne.layer.shadowOpacity = 0.6;
    self.viewOne.layer.shouldRasterize = YES;
    self.viewOne.layer.shadowRadius = 2;

    self.viewTwo.layer.shadowColor = [[UIColor grayColor] CGColor];
    self.viewTwo.layer.shadowOffset = CGSizeMake(2, 2);
    self.viewTwo.layer.shadowOpacity = 0.6;
    self.viewTwo.layer.shouldRasterize = YES;
    self.viewTwo.layer.shadowRadius = 2;

    self.viewThree.layer.shadowColor = [[UIColor grayColor] CGColor];
    self.viewThree.layer.shadowOffset = CGSizeMake(2, 2);
    self.viewThree.layer.shadowOpacity = 0.6;
    self.viewThree.layer.shouldRasterize = YES;
    self.viewThree.layer.shadowRadius = 2;
}
于 2011-06-03T04:06:35.713 回答