1
이미지보기를 만들고 해당보기에서 이미지를 설정하고 이미지보기를 스크롤보기의 하위보기 (예 : 슬라이드 쇼 이미지)로 추가했습니다. 그래서 이미지 뷰 프레임 크기를 설정하고 뷰 프레임 크기를 동적으로 설정하려고합니다. 세로 및 가로 모드에서 다른 이미지보기 프레임 크기와 스크롤보기 크기를 설정하고 싶습니다. 그렇다면 가로 및 세로 모드에서 다른 프레임 크기를 어떻게 설정할 수 있습니까? 여기 iPhone의 Orientations에서 다른 이미지보기 프레임 크기를 설정하는 방법은 무엇입니까?
내 샘플 코드
,- (void)viewDidLoad {
[super viewDidLoad];
self.scroll = [[UIScrollView alloc] init];
self.scroll.delegate = self;
self.scroll.pagingEnabled = YES;
self.scroll.contentMode = UIViewContentModeScaleAspectFit;
self.scroll.autoresizingMask = (UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth);
[self.view addSubview:self.scroll];
totalArray = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:@"dashboard_demo_2.png"],
[UIImage imageNamed:@"dashboard_demo_1.png"],
[UIImage imageNamed:@"dashboard_demo_2.png"],
[UIImage imageNamed:@"3.jpg"],
[UIImage imageNamed:@"4.jpg"],
[UIImage imageNamed:@"12.jpg"],
[UIImage imageNamed:@"5.jpg"],nil];
x = 0;
for(int i = 0; i< [totalArray count]; i++)
{
img = [[UIImageView alloc] initWithFrame:CGRectMake(x, 0, 320, 200)];
img.image =[totalArray objectAtIndex:i];
x = x+320; // in portait mode if the image sets correctly, but landscape mode it will x = x + 480;
[self.scroll addSubview:img];
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait ||
orientation == UIDeviceOrientationPortraitUpsideDown)
{
[self portraitMode];
}
else if (orientation == UIDeviceOrientationLandscapeLeft ||
orientation == UIDeviceOrientationLandscapeRight)
{
[self LandscapeMode];
}
return YES;
}
-(void) portraitMode
{
//How to set the frame sizes.
self.scroll.frame = CGRectMake(0, 0, 320, 200);
img.frame = CGRectMake(x, 0, 320, 200);
scroll.contentSize = CGSizeMake(x, 200); // it doesn't set
}
-(void) LandscapeMode
{
//How to set the frame sizes
self.scroll.frame = CGRectMake(0, 0, 480, 320);
img.frame = CGRectMake(x, 0, 480, 200);
scroll.contentSize = CGSizeMake(x, 320); // it doesn't set
}
저를 도와주세요.
감사합니다.