당신은 아마 당신의있는 ScrollView 및 이미지를 조정하는 루틴을 원하는 (또는 내 경우에는, 이미지 버튼) 알고있는 경우 scrollview (스크롤 뷰의 autoSizingMask
을 방향이 바뀔 때 늘어나도록 설정해야합니다).
예를 들어, 다음과 같은 루틴이 있습니다. UIButton이 이미 각 아이콘에 추가 된 상태에서 만든 scrollview가 있다고 가정합니다.이 기본 아이디어는 UIImageViews를 사용하는 경우에도 작동합니다. 하지만) :
- (void)rearrangeImages
{
if (!_listOfImages)
{
[self loadImages];
return;
}
// a few varibles to keep track of where I am
int const imageWidth = [self thumbnailSize];
int const imagesPerRow = self.view.frame.size.width/(imageWidth + 2);
int const imageHeight = imageWidth;
int const imagePadding = (self.view.frame.size.width - imageWidth*imagesPerRow)/(imagesPerRow + 1);
int const cellWidth = imageWidth + imagePadding;
int const cellHeight = imageHeight + imagePadding;
NSInteger row;
NSInteger column;
NSInteger index;
CGRect newFrame;
// iterate through the buttons
for (UIView *button in [_scrollView subviews])
{
index = [button tag];
if ([button isKindOfClass:[UIButton class]] && index < [_listOfImages count])
{
// figure out where the button should go
row = floor(index/imagesPerRow);
column = index % imagesPerRow;
newFrame = CGRectMake(column * cellWidth + imagePadding,
row * cellHeight,
imageWidth,
imageHeight);
if (button.frame.origin.x != newFrame.origin.x || button.frame.origin.y != newFrame.origin.y)
[button setFrame:newFrame];
}
}
NSInteger numberOfRows = floor(([_listOfImages count] - 1)/imagesPerRow) + 1;
[_scrollView setContentSize:CGSizeMake(self.view.frame.size.width, numberOfRows * cellHeight)];
}
그럼 예를 들어 내 응용 프로그램 호출이 화면이 변화 방향, 당신은 사전에서 iOS 5를 지원하는 경우
- (void)viewWillLayoutSubviews
{
[self rearrangeImages];
}
, 당신은 또한 같은해야 할 수도 있습니다
를
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
float iOSversion = [[[UIDevice currentDevice] systemVersion] floatValue];
// we don't need to do this in iOS 5, because viewWillLayoutSubviews is automatically called
if (iOSversion < 5.0)
[self viewWillLayoutSubviews];
}
출처
2012-07-09 18:22:49
Rob
화면을 채우지 만 행당 3 개 항목을 유지하거나 그리드 크기를 변경 하시겠습니까? 세로 3 개, 가로 5 개를 세로로 말하십시오. – George
수정 -> "초상화 3 행당 항목 및 가로 5 항목 행 당." – Dave
내가 scrollview에 이미지를 넣을 때, 나는 "행"에 들어갈 수있는 숫자를 알아 내고 모든 이미지에 대해 프레임을 설정합니다 따라서. 그런 다음 오리엔테이션이 변경되고 컨트롤을 다시 배치해야 할 때마다 iOS 5에서 호출되는 'viewWillLayoutSubviews'에서이 내용을 다시 호출합니다. 예를 들어 나의 대답을보십시오. 이것은 분명히 내 애플 리케이션에 특정이지만, 그것이 작동하는 방법에 대한 기본적인 감각을 제공해야합니다. 옆으로, scrollview가 양쪽 방향에서 얼마나 넓게 있는지주의 깊게 생각하고 양쪽에서 멋지게 렌더링되는 이미지 크기를 선택하는 것이 좋습니다. – Rob