iOS : 프로그래밍 방식으로 스크린 샷을 만드는 가장 빠르고 효과적인 방법은 무엇입니까?

Swalkner

내 iPad 앱에서 화면의 큰 부분을 차지하는 UIView의 스크린 샷을 만들고 싶습니다. 안타깝게도 하위 뷰는 매우 깊숙이 중첩되어 있으므로 스크린 샷을 만들고 나중에 페이지 컬링을 애니메이션하는 데 시간이 오래 걸립니다.

"일반적인"방법보다 빠른 방법이 있습니까?

UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

가능하다면 내 뷰를 캐싱하거나 재구성하는 것을 피하고 싶습니다.

3lvis

가능할 때마다 스냅 샷 API를 사용하는 더 나은 방법을 찾았습니다.

도움이되기를 바랍니다.

class func screenshot() -> UIImage {
    var imageSize = CGSize.zero

    let orientation = UIApplication.shared.statusBarOrientation
    if UIInterfaceOrientationIsPortrait(orientation) {
        imageSize = UIScreen.main.bounds.size
    } else {
        imageSize = CGSize(width: UIScreen.main.bounds.size.height, height: UIScreen.main.bounds.size.width)
    }

    UIGraphicsBeginImageContextWithOptions(imageSize, false, 0)
    for window in UIApplication.shared.windows {
        window.drawHierarchy(in: window.bounds, afterScreenUpdates: true)
    }

    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return image!
}

iOS 7 스냅 샷에 대해 더 알고 싶으십니까?

Objective-C 버전 :

+ (UIImage *)screenshot
{
    CGSize imageSize = CGSizeZero;

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if (UIInterfaceOrientationIsPortrait(orientation)) {
        imageSize = [UIScreen mainScreen].bounds.size;
    } else {
        imageSize = CGSizeMake([UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
    }

    UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
        CGContextSaveGState(context);
        CGContextTranslateCTM(context, window.center.x, window.center.y);
        CGContextConcatCTM(context, window.transform);
        CGContextTranslateCTM(context, -window.bounds.size.width * window.layer.anchorPoint.x, -window.bounds.size.height * window.layer.anchorPoint.y);
        if (orientation == UIInterfaceOrientationLandscapeLeft) {
            CGContextRotateCTM(context, M_PI_2);
            CGContextTranslateCTM(context, 0, -imageSize.width);
        } else if (orientation == UIInterfaceOrientationLandscapeRight) {
            CGContextRotateCTM(context, -M_PI_2);
            CGContextTranslateCTM(context, -imageSize.height, 0);
        } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
            CGContextRotateCTM(context, M_PI);
            CGContextTranslateCTM(context, -imageSize.width, -imageSize.height);
        }
        if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
            [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];
        } else {
            [window.layer renderInContext:context];
        }
        CGContextRestoreGState(context);
    }

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Windows Phone에서 프로그래밍 방식으로 스크린 샷을 찍는 방법은 무엇입니까?

Android에서 프로그래밍 방식으로 스크린 샷을 찍는 방법은 무엇입니까?

프로그래밍 방식 (iOS)으로 Firebase 동적 링크를 만드는 방법은 무엇입니까?

장고 쿼리 셋의 스냅 샷을 만드는 가장 효율적인 방법은 무엇입니까?

프로그래밍 방식으로 스크린 샷을 찍고 PNG로 저장

프로그래밍 방식으로 WHOLE 활동 페이지의 스크린 샷을 만드는 방법은 무엇입니까?

IOS에서 프로그래밍 방식으로 UICollectionViewCell을 스크롤하는 방법은 무엇입니까?

Aero 효과로 스크린 샷을 찍는 방법은 무엇입니까?

ReactJS 안드로이드 앱에서 프로그래밍 방식으로 스크린샷을 찍는 방법은 무엇입니까?

빠르고 점차적으로 느린 간격을 만드는 방법은 무엇입니까?

전체적으로 스크린 샷을 올바르게 찍는 방법은 무엇입니까?

Android에서 열린 현재 활동의 스크린 샷을 프로그래밍 방식으로 찍는 방법은 무엇입니까?

프로그래밍 방식으로 iOS 장치 볼륨을 변경하는 방법은 무엇입니까?

Python으로 보고서에 스크린 샷을 추가하는 방법은 무엇입니까?

iOS : 프로그래밍 방식으로 YTPlayerView를 인스턴스화하는 방법은 무엇입니까?

iOS에서 프로그래밍 방식으로 스크린 샷을 찍는 방법

서비스 내에서 프로그래밍 방식으로 항목을 만드는 가장 좋은 방법은 무엇입니까?

프로그래밍 방식으로 iPad 홈 화면의 스크린 샷을 찍는 방법은 무엇입니까?

Swift에서 프로그래밍 방식으로 앱의 스크린 샷을 찍으려고 할 때 스크린 샷이 흰색으로 표시되는 이유는 무엇입니까?

iOS 장치의 화면 자동 잠금 시간 초과 시간을 프로그래밍 방식으로 읽는 방법은 무엇입니까?

Xcode에서 App Store 용 장치 베젤로 스크린 샷을 만드는 방법은 무엇입니까?

Android-화면 크기와 버튼에 따라 프로그래밍 방식으로 버튼을 동적으로 추가하는 방법은 무엇입니까?

UIView 스크린 샷을 더 빠르게 찍는 방법은 무엇입니까?

프로그래밍 방식으로 지시문을 인스턴스화하고 적용하는 방법은 무엇입니까?

iOS에서 통화가 보류중인 것을 프로그래밍 방식으로 감지하는 방법은 무엇입니까?

프로그래밍 방식으로 동적 리소스 키 이름을 얻는 방법은 무엇입니까?

iOS8에서 스토리 보드없이 프로그래밍 방식으로 Today 위젯을 만드는 방법은 무엇입니까?

JavaScript로 div의 스크린 샷을 만드는 방법은 무엇입니까?

Android-프로그래밍 방식으로 스크린 샷을 찍는 방법

TOP 리스트

  1. 1

    Ionic 2 로더가 적시에 표시되지 않음

  2. 2

    JSoup javax.net.ssl.SSLHandshakeException : <url>과 일치하는 주체 대체 DNS 이름이 없습니다.

  3. 3

    std :: regex의 일관성없는 동작

  4. 4

    Xcode10 유효성 검사 : 이미지에 투명성이 없지만 여전히 수락되지 않습니까?

  5. 5

    java.lang.UnsatisfiedLinkError : 지정된 모듈을 찾을 수 없습니다

  6. 6

    rclone으로 원격 디렉토리의 모든 파일을 삭제하는 방법은 무엇입니까?

  7. 7

    상황에 맞는 메뉴 색상

  8. 8

    SMTPException : 전송 연결에서 데이터를 읽을 수 없음 : net_io_connectionclosed

  9. 9

    정점 셰이더에서 카메라에서 개체까지의 XY 거리

  10. 10

    Windows cmd를 통해 Anaconda 환경에서 Python 스크립트 실행

  11. 11

    다음 컨트롤이 추가되었지만 사용할 수 없습니다.

  12. 12

    C #에서 'System.DBNull'형식의 개체를 'System.String'형식으로 캐스팅 할 수 없습니다.

  13. 13

    JNDI를 사용하여 Spring Boot에서 다중 데이터 소스 구성

  14. 14

    Cassandra에서 버전이 지정된 계층의 효율적인 모델링

  15. 15

    복사 / 붙여 넣기 비활성화

  16. 16

    Android Kotlin은 다른 활동에서 함수를 호출합니다.

  17. 17

    Google Play Console에서 '예기치 않은 오류가 발생했습니다. 나중에 다시 시도해주세요. (7100000)'오류를 수정하는 방법은 무엇입니까?

  18. 18

    SQL Server-현명한 데이터 문제 받기

  19. 19

    Seaborn에서 축 제목 숨기기

  20. 20

    ArrayBufferLike의 typescript 정의의 깊은 의미

  21. 21

    Kubernetes Horizontal Pod Autoscaler (HPA) 테스트

뜨겁다태그

보관