gpt4 book ai didi

iphone - 向兼容 iOS 3.0 的 UIView 添加轮廓阴影

转载 作者:行者123 更新时间:2023-12-03 20:57:28 25 4
gpt4 key购买 nike

我有两个 UIViewController A 和 B,它们作为 subview 添加到 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 中做一些魔法,但这可能吗?或者我只能在 View 的边界内绘制?

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

干杯objneodude

最佳答案

通过以下代码解决

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

关于iphone - 向兼容 iOS 3.0 的 UIView 添加轮廓阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4022153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com