2017-11-19 16 views
0

두 개의 자식 뷰 인 detailView라는 UIView, detailTextView라는 UITextView 및 detailImageView라는 UIImageView가 서로의 형제 인 UIView가 있습니다. detailView는 분할 뷰에서 기본 세부 UIView 내에 포함됩니다. 내 메인 스토리 보드에서이 모든 것을 설정하기 위해 자동 크기 조정을 사용하고 있습니다. 다음,장치가 회전 할 때 인세 트 UITextView 크기 조정

Top Layout Guide 
Bottom Layout Guide 
View 
- Detail View 
- - Detail Text View 
- - Detail Image View 
Navigation Item 

detailTextView 각 측으로부터 삽입 된 10 % 뷰가 나타날 때 흐려진 및 이미지 위에 상호 용해를 갖는다 : 시각, 계층 구조는 다음과 같다

/** 
- reference: 
Joy, V. (2016, December 15). Swift 3: How to create blurred side edges/ 
corners of a UIImageView?. Message posted to 
https://stackoverflow.com/a/41158594/6084947 
*/ 
internal override func viewDidAppear(_ animated: Bool) { 
    print("detailViewDidAppear") 

    super.viewDidAppear(animated) 

    // Resize the text view. 
    let inset = detailView.bounds.width * 0.2 
    detailTextView.frame = CGRect(
     x: inset/2, 
     y: inset/2, 
     width: detailView.bounds.width - inset, 
     height: detailView.bounds.height - inset 
    ) 

    // Set up text view attributes. 
    detailTextView.allowsEditingTextAttributes = true 

    let xInset = detailTextView.bounds.width * 0.05 
    let yInset = detailTextView.bounds.height * 0.05 
    detailTextView.textContainerInset = UIEdgeInsetsMake(
     yInset, 
     xInset, 
     yInset, 
     xInset 
    ) 

    // Blur edges of text view (see Joy, 2016). 
    let maskLayer = CAGradientLayer() 
    maskLayer.frame = detailTextView.bounds 
    maskLayer.shadowRadius = 5 
    maskLayer.shadowPath = CGPath(
     roundedRect: detailTextView.bounds.insetBy(dx: 5, dy: 5), 
     cornerWidth: 10, 
     cornerHeight: 10, 
     transform: nil 
    ) 
    maskLayer.shadowOpacity = 1 
    maskLayer.shadowOffset = CGSize.zero 
    maskLayer.shadowColor = UIColor.white.cgColor 
    detailTextView.layer.mask = maskLayer 

    // Fade in text view. 
    UIView.transition(
     with: detailView, 
     duration: 3, 
     options: .transitionCrossDissolve, 
     animations: 
     { self.detailView.bringSubview(toFront: self.detailTextView) }, 
     completion: nil 
    ) 
} 

화면이 회전 할 때 inset detailTextView의 크기가 제대로 조정되지 않는 것이 문제입니다. 가로보기 모드에서 세부보기를로드 할 때 iPad 시뮬레이터에서 세로보기 모드로 회전 할 때 수퍼보기가 채워지지 않습니다.

internal override func viewWillTransition(
    to size: CGSize, 
    with coordinator: UIViewControllerTransitionCoordinator) 
{ 
    print("viewWillTransition") 

    super.viewWillTransition(to: size, with: coordinator) 

    coordinator.animate(alongsideTransition: nil) { 
     [unowned self] _ in 

     // Resize text view. 
     let inset = size.width * 0.2 
     self.detailTextView.frame = CGRect(
      x: inset/2, 
      y: inset/2, 
      width: size.width - inset, 
      height: size.height - inset 
     ) 
    } 
} 

불행하게도,이 풍경 - 투 - 세로 전환을 돕고 조정하는 경계의 무리와 함께 나에게 잎하지 않습니다

나는 다음과 같은 시도했습니다. 어떤 제안?

+0

크기 클래스가 동일한 분할 화면 모드의 일부 유형하지 않는 한 . 'size'를 사용하지 마십시오. 대신에 - 당신은 올바른 오버 라이드를 가지고 있습니다 - 메인 뷰의'bounds'를 사용하십시오. (즉, 당신은 IMO가 올바른 것을 가지고있다.) – dfd

+0

고마워,하지만'size'를'self.view.bounds'로 바꾸는 것은 도움이되지 않았다. 가로 방향에서 세로 방향으로 회전 할 때 텍스트보기는 확대되어 화면의 아래쪽 절반을 채 웁니다. – michaelgill1969

+0

BTW에는 iPad의 가로 모드에있을 때 분할보기의 마스터와 세부 정보가 모두 표시됩니다. – michaelgill1969

답변

0

문제는 UITextView 또는 인세 트의 크기가 아니 었습니다. 일부 인쇄 문과 함께 예상대로 자동으로 작동하고있었습니다. 오히려 문제는 가장자리를 흐리게하기 위해 만든 마스크 레이어의 크기가 조정되지 않았다는 것입니다. 다음 (insetBy를 사용 (DX : :) DY는 대신 프레임의 UITextView의 경계를 변경할 수는) 내 수정 코드 : 아이 패드에 대한

/** 
- reference: 
Joy, V. (2016, December 15). Swift 3: How to create blurred side edges/ 
corners of a UIImageView?. Message posted to 
https://stackoverflow.com/a/41158594/6084947 
*/ 
internal override func viewDidAppear(_ animated: Bool) { 
    print("detailViewDidAppear") 

    super.viewDidAppear(animated) 

    // Resize the text view. 
    let textViewInset = detailView.bounds.width * 0.1 
    detailTextView.bounds = detailView.bounds.insetBy(
     dx: textViewInset, 
     dy: textViewInset 
    ) 

    // Set up text view attributes. 
    detailTextView.allowsEditingTextAttributes = true 

    let textContainerInset = detailTextView.bounds.width * 0.05 
    detailTextView.textContainerInset = UIEdgeInsetsMake(
     textContainerInset, 
     textContainerInset, 
     textContainerInset, 
     textContainerInset 
    ) 

    // Blur edges of text view (see Joy, 2016). 
    let maskLayer = CAGradientLayer() 
    maskLayer.frame = detailTextView.bounds 
    maskLayer.shadowRadius = 5 
    maskLayer.shadowPath = CGPath(
     roundedRect: detailTextView.bounds.insetBy(dx: 5, dy: 5), 
     cornerWidth: 10, 
     cornerHeight: 10, 
     transform: nil 
    ) 
    maskLayer.shadowOpacity = 1 
    maskLayer.shadowOffset = CGSize.zero 
    maskLayer.shadowColor = UIColor.white.cgColor 
    detailTextView.layer.mask = maskLayer 

    // Fade in text view. 
    UIView.transition(
     with: detailView, 
     duration: 3, 
     options: .transitionCrossDissolve, 
     animations: 
     { self.detailView.bringSubview(toFront: self.detailTextView) }, 
     completion: nil 
    ) 
} 

/** 
- reference: 
Joy, V. (2016, December 15). Swift 3: How to create blurred side edges/ 
corners of a UIImageView?. Message posted to 
https://stackoverflow.com/a/41158594/6084947 
*/ 
internal override func viewWillTransition(
    to size: CGSize, 
    with coordinator: UIViewControllerTransitionCoordinator) 
{ 
    print("viewWillTransition") 

    super.viewWillTransition(to: size, with: coordinator) 

    coordinator.animate(alongsideTransition: nil) { 
     [unowned self] _ in 

     // Blur edges of text view (see Joy, 2016). 
     let maskLayer = CAGradientLayer() 
     maskLayer.frame = self.detailTextView.bounds 
     maskLayer.shadowRadius = 5 
     maskLayer.shadowPath = CGPath(
      roundedRect: self.detailTextView.bounds.insetBy(dx: 5, dy: 5), 
      cornerWidth: 10, 
      cornerHeight: 10, 
      transform: nil 
     ) 
     maskLayer.shadowOpacity = 1 
     maskLayer.shadowOffset = CGSize.zero 
     maskLayer.shadowColor = UIColor.white.cgColor 
     self.detailTextView.layer.mask = maskLayer 
    } 
}