당신이
-(CGRect) unobscuredBounds
{
CGRect bounds = [self.view bounds];
return UIEdgeInsetsInsetRect(bounds, [self defaultContentInsets]);
}
-(UIEdgeInsets) defaultContentInsets
{
const CGFloat topOverlay = self.topLayoutGuide.length;
const CGFloat bottomOverlay = self.bottomLayoutGuide.length;
return UIEdgeInsetsMake(topOverlay, 0, bottomOverlay, 0);
}
당신은 쉽게 재사용에 대한 category에 넣고 수 있어야합니다.
이 메서드는 회전 후에 뷰 크기가 조정될 때 발생하는 변경 사항을 올바르게 처리합니다. 즉, UINavigationBar 크기의 변경이 올바르게 처리됩니다. centre content by adjusting insets이를 사용하려면 내용에게
을 중심으로
, 당신은 같은 것을 할 것 :
-(void) scrollViewDidZoom:(UIScrollView *)scrollView
{
[self centerContent];
}
- (void)centerContent
{
const CGSize contentSize = self.scrollView.contentSize;
const CGSize unobscuredBounds = [self unobscuredBounds].size;
const CGFloat left = MAX(0, (unobscuredBounds.width - contentSize.width)) * 0.5f;
const CGFloat top = MAX(0, (unobscuredBounds.height - contentSize.height)) * 0.5f;
self.scrollView.contentInset = UIEdgeInsetsMake(top, left, top, left);
}
귀하의 콘텐츠 세트 지금 (은폐되지 않도록하기 위해)이 필요로하는 기본 세트의 값을 반영합니다 또한 중심에 잘 맞게 삽입해야 할 필요가 있습니다. 회전 & 확대
처리
당신은 아마도 가로 및 세로 사이에 애니메이션을 때를 중심으로 수행 할. 동시에 콘텐츠가 항상 맞을 수 있도록 최소 확대/축소 배율을 조정할 수 있습니다.
-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self centerContent];
const bool zoomIsAtMinimum = self.scrollView.zoomScale == self.scrollView.minimumZoomScale;
self.scrollView.minimumZoomScale = [self currentMinimumScale];
if(zoomIsAtMinimum)
{
self.scrollView.zoomScale = self.scrollView.minimumZoomScale;
}
}
-(CGFloat) currentMinimumScale
{
const CGFloat currentScale = self.scrollView.zoomScale;
const CGSize scaledContentSize = self.scrollView.contentSize;
const CGSize scrollViewSize = [self unobscuredBounds].size;
CGFloat scaleToFitWidth = currentScale * scrollViewSize.width/scaledContentSize.width;
CGFloat scaleToFitHeight = currentScale * scrollViewSize.height/scaledContentSize.height;
return MIN(scaleToFitWidth, scaleToFitHeight);
}
willAnimateRotationToInterfaceOrientation:…
방법은보기 애니메이션 블록 내에서 호출, 그래서 당신이 가로에서 세로 전환으로 좋은 부드러운 애니메이션의 변화로 이어질 것입니다 적용되는 변경 :이 같은 것을 사용해보십시오.