想要在视图上显示图像,但是采用半圆形

时间:2012-01-18 06:03:59

标签: iphone objective-c ios uiimageview

我想在整个屏幕上在iPhone应用程序中显示图像,但是具有半曲线形状。 图像应从角落触摸开始,并在触摸另一角落时结束。我没有想法让任何人都可以帮助我。 此图像表是半弯曲的,但图像应显示在半弯曲形状上

This image table is semi curved but image should be displayed on semi curved shape

1 个答案:

答案 0 :(得分:0)

使用CALayer可以将图像更改为曲线或播放图像。每个imageView都有一层。用它来显示效果。您可以通过以下代码实现您对桌面图像的效果: -

-(void) viewDidLoad{

   [self paperCurlShadowImage];
}

-(void) paperCurlShadowImage{

        imgView = [[UIImageView alloc] initWithImage:image];
        imgView.frame=CGRectMake(0, 0, image.size.width, image.size.height);


        [self.view addSubview:imgView];

        imgView.layer.shadowColor = [UIColor blackColor].CGColor;
        imgView.layer.shadowOpacity = 0.7f;
        imgView.layer.shadowOffset = CGSizeMake(10.0f, 10.0f);
        imgView.layer.shadowRadius = 2.0f;
        imgView.layer.masksToBounds = NO;


        imgView.layer.shadowPath = [self renderPaperCurl:imgView];
        [imgView release];

}

- (CGPathRef)renderPaperCurl:(UIView*)imgView1 {
    CGSize size = imgView1.bounds.size;
    CGFloat curlFactor = 15.0f;
    CGFloat shadowDepth = 5.0f;

    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(0.0f, 0.0f)];
    [path addLineToPoint:CGPointMake(size.width, 0.0f)];
    [path addLineToPoint:CGPointMake(size.width, size.height + shadowDepth)];
    [path addCurveToPoint:CGPointMake(0.0f, size.height + shadowDepth)
            controlPoint1:CGPointMake(size.width - curlFactor, size.height + shadowDepth - curlFactor)
            controlPoint2:CGPointMake(curlFactor, size.height + shadowDepth - curlFactor)];

    return path.CGPath;
}