1
我有一個問題,我想阻止橫向應用程序,並顯示圖片768 * 1024((橫向大小的ipad),但應用程序不停留在橫向+滾動視圖在1024 * 1024時在景觀,上面用我的UIScrollView的代碼的某些部分,其顯示PNG:UIScrollView調整大小
const CGFloat kScrollObjHeight = 768.0;
const CGFloat kScrollObjWidth = 1024.0;
const NSUInteger kNumImages = 46;
- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [FirstScrollView subviews];
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += (kScrollObjWidth);
}
}
// set the content size so it can be scrollable
[FirstScrollView setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [FirstScrollView bounds].size.height)];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[FirstScrollView setBackgroundColor:[UIColor blackColor]];
[FirstScrollView setCanCancelContentTouches:NO];
FirstScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
FirstScrollView.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
FirstScrollView.scrollEnabled = YES;
FirstScrollView.pagingEnabled = YES;
// FirstScrollView.frame = CGRectMake(0, 0, 1024, 768);
NSUInteger i;
for (i = 1; i <= kNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:@"page%d.png", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i;
[FirstScrollView addSubview:imageView];
[imageView release];
}
[self layoutScrollImages];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//return YES;
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft;
}