“renderInContext:” and CATransform3D

后端 未结 3 863
粉色の甜心
粉色の甜心 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:38

    May Be You can use Core Graphaic instead of CATransform3DMakeRotation :)

    CGAffineTransform flip = CGAffineTransformMakeScale(1.0, -1.0);
    

    Which get effet on the renderInContext

    0 讨论(0)
  • 2021-02-04 21:45

    I got it working with protocols.... I'm implementing a protocol in all UIViews classes that make 3D transforms. So when I request a screenshot, it make all subviews screenshot, and generate one UIImage.. Not so good for lots of views, but I'm doing in a few views.

    #pragma mark - Protocol implementation 'TDITransitionCustomTransform'
    
    //Conforms to "TDITransitionCustomTransform" protocol, return currrent image view state , by current layer
    
    - (UIImage*)imageForCurrentState {
    
    //Make print
    
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0);
    
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    
    UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    //return printed image
    
    return screenShot;
    
    }
    

    I was thinking it may works now because I'm doing that render in the transformed view layer, which have being transformed it self... And it wasn't working because "renderInContext:" doesn't get layers of it subviews, may it possible ?

    Anyone interest in a bit more code of this solution, can be found here . in the apple dev forum.

    It may be a function bug, or it just not being design for this purpose ...

    0 讨论(0)
  • 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;
    }
    
    0 讨论(0)
提交回复
热议问题