繁体   English   中英

向UIImageView添加反射的最有效方法是什么

[英]What is the most efficient way to add a reflection to a UIImageView

我只想要一个最容易在UIImageVies下进行反射的方法,这个方法很容易管理。

只需使用iPhone SDK库中示例代码即可

更新 :链接现已更新到新位置

正如Phil所说,你可以有一个“反映”的UIImageView实例:

@interface ReflectedImageView : UIView 
{
@private
    UIImageView *_imageView;
    UIImageView *_imageReflectionView;
}

@property (nonatomic, retain) UIImage *image;

@end

然后,在您的实现中,这样的事情

@implementation ReflectedImageView

@dynamic image;

- (id)initWithFrame:(CGRect)frame 
{
    if (self = [super initWithFrame:frame]) 
    {
        self.backgroundColor = [UIColor clearColor];

        // This should be the size of your image:
        CGRect rect = CGRectMake(0.0, 0.0, 320.0, 290.0);

        _imageReflectionView = [[UIImageView alloc] initWithFrame:rect];
        _imageReflectionView.contentMode = UIViewContentModeScaleAspectFit;
        _imageReflectionView.alpha = 0.4;
        _imageReflectionView.transform = CGAffineTransformMake(1, 0, 0, -1, 0, 290.0);
        [self addSubview:_imageReflectionView];

        _imageView = [[UIImageView alloc] initWithFrame:rect];
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:_imageView];
    }
    return self;
}

- (void)setImage:(UIImage *)newImage
{
    _imageView.image = newImage;
    _imageReflectionView.image = newImage;
}

- (UIImage *)image
{
    return _imageView.image;
}

- (void)dealloc 
{
    [_imageView release];
    [_imageReflectionView release];
    [super dealloc];
}

@end

我写了一篇关于如何生成任何UI元素或元素组的反射的文章。 罐装技术可以放入您的项目中,并且非常易于使用。 源代码和文章可以在http://aptogo.co.uk/2011/08/no-fuss-reflections/找到

最简单的方法是在Photoshop中手动完成! (严重的 - 如果那是切实可行的)。

否则,您需要制作图像的反转副本(或至少下半部分)以放置在真实的图像下方,覆盖黑色渐变(假设您的背景为黑色),alpha = 1到alpha = 0。

如果你需要将它放在任意背景上,它会更复杂,因为你必须将alpha = 0到alpha = 1的渐变应用到你的倒像。 我敲了一些代码就做了 - 当我到达我的Mac时会尝试挖出来,如果没有其他人早点拿出任何东西。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM