“renderInContext:” and CATransform3D

后端 未结 3 855
粉色の甜心
粉色の甜心 2021-02-04 21:27

I have an view that have mutiples views inside it, and an image presentation (aka. \'cover flow\') into that too... And I need to make a screenshot programatically !

Sin

3条回答
  •  执念已碎
    2021-02-04 21:57

    have you actually tried it? I'm currently working on a project with several 3D transforms, and when I try to programmatically make this screenshot it works just fine :) Here is the code I use:

    -(UIImage *)getScreenshot
    {
        CGFloat scale = 1.0;
        if([[UIScreen mainScreen]respondsToSelector:@selector(scale)])
        {        
            CGFloat tmp = [[UIScreen mainScreen]scale];
            if (tmp > 1.5)
            {
                scale = 2.0;    
            }
        }      
        if(scale > 1.5)
        {
            UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, scale);
        } 
        else
        {
            UIGraphicsBeginImageContext(self.frame.size);
        }    
        //SELF HERE IS A UIVIEW
        [self.layer renderInContext:UIGraphicsGetCurrentContext()];    
        UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return screenshot;
    }
    

提交回复
热议问题