美文网首页iOS开发者进阶
iOS 17.0 YYText UIGraphicsBeginI

iOS 17.0 YYText UIGraphicsBeginI

作者: __Mr_Xie__ | 来源:发表于2024-02-24 17:43 被阅读0次

    YYTextAsyncLayer崩溃问题修复

    //        UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, self.contentsScale);
    //        CGContextRef context = UIGraphicsGetCurrentContext();
    //        if (self.opaque) {
    //            CGSize size = self.bounds.size;
    //            size.width *= self.contentsScale;
    //            size.height *= self.contentsScale;
    //            CGContextSaveGState(context); {
    //                if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) {
    //                    CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
    //                    CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
    //                    CGContextFillPath(context);
    //                }
    //                if (self.backgroundColor) {
    //                    CGContextSetFillColorWithColor(context, self.backgroundColor);
    //                    CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
    //                    CGContextFillPath(context);
    //                }
    //            } CGContextRestoreGState(context);
    //        }
    //        task.display(context, self.bounds.size, ^{return NO;});
    //        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    //        UIGraphicsEndImageContext();
    //        self.contents = (__bridge id)(image.CGImage);
            UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
                  format.opaque = self.opaque;
                  format.scale = self.contentsScale;
    
                  UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:self.bounds.size format:format];
                  UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
                      CGContextRef context = rendererContext.CGContext;
                      if (self.opaque) {
                          CGSize size = self.bounds.size;
                          size.width *= self.contentsScale;
                          size.height *= self.contentsScale;
                          CGContextSaveGState(context); {
                              if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) {
                                  CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
                                  CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
                                  CGContextFillPath(context);
                              }
                              if (self.backgroundColor) {
                                  CGContextSetFillColorWithColor(context, self.backgroundColor);
                                  CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
                                  CGContextFillPath(context);
                              }
                          } CGContextRestoreGState(context);
                      }
                      task.display(context, self.bounds.size, ^{return NO;});
                  }];
    
                  self.contents = (__bridge id)(image.CGImage);
    

    YBImageBrowser崩溃问题修复

    UIImage *YBIBSnapshotView(UIView *view) {
    //    UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, [UIScreen mainScreen].scale);
    //    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
    //    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    //    UIGraphicsEndImageContext();
        
        CGSize size = view.bounds.size;
        UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
        format.scale = [UIScreen mainScreen].scale;
        UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size format:format];
        UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
        }];
        return image;
    }
    

    相关文章

      网友评论

        本文标题:iOS 17.0 YYText UIGraphicsBeginI

        本文链接:https://www.haomeiwen.com/subject/dudoadtx.html