내 응용 프로그램에서 사진 응용 프로그램에 사용 된 것과 비슷한 전체 화면 사진 뷰어를 사용자에게 제공하고 싶습니다. 이것은 단지 하나의 사진을위한 것이므로 매우 간단해야합니다. 사용자가이 사진을 확대/축소 및 이동하는 기능으로 볼 수 있기를 바랍니다.전체 화면 UIScrollView 내에서 UIImageView를 가운데에 배치하는 방법은 무엇입니까?
나는 대부분 작동하고 있습니다. 그리고 UIImageView를 가운데에 배치하지 않으면 모든 것이 완벽하게 작동합니다. 그러나, 나는 UIImageView가 이미지가 충분히 축소되었을 때 화면의 중앙에 놓기를 정말로 원합니다. 스크롤 뷰의 왼쪽 위 모서리에 붙어 있기를 원하지 않습니다.
이 뷰를 중앙에 놓으면 수직 스크롤 가능 영역이 원래보다 커야합니다. 따라서 조금 확대 한 후에는 이미지 상단에서 약 100 픽셀 스크롤 할 수 있습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
@interface MyPhotoViewController : UIViewController <UIScrollViewDelegate>
{
UIImage* photo;
UIImageView *imageView;
}
- (id)initWithPhoto:(UIImage *)aPhoto;
@end
@implementation MyPhotoViewController
- (id)initWithPhoto:(UIImage *)aPhoto
{
if (self = [super init])
{
photo = [aPhoto retain];
// Some 3.0 SDK code here to ensure this view has a full-screen
// layout.
}
return self;
}
- (void)dealloc
{
[photo release];
[imageView release];
[super dealloc];
}
- (void)loadView
{
// Set the main view of this UIViewController to be a UIScrollView.
UIScrollView *scrollView = [[UIScrollView alloc] init];
[self setView:scrollView];
[scrollView release];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Initialize the scroll view.
CGSize photoSize = [photo size];
UIScrollView *scrollView = (UIScrollView *)[self view];
[scrollView setDelegate:self];
[scrollView setBackgroundColor:[UIColor blackColor]];
// Create the image view. We push the origin to (0, -44) to ensure
// that this view displays behind the navigation bar.
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, -44.0,
photoSize.width, photoSize.height)];
[imageView setImage:photo];
[scrollView addSubview:imageView];
// Configure zooming.
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
CGFloat widthRatio = screenSize.width/photoSize.width;
CGFloat heightRatio = screenSize.height/photoSize.height;
CGFloat initialZoom = (widthRatio > heightRatio) ? heightRatio : widthRatio;
[scrollView setMaximumZoomScale:3.0];
[scrollView setMinimumZoomScale:initialZoom];
[scrollView setZoomScale:initialZoom];
[scrollView setBouncesZoom:YES];
[scrollView setContentSize:CGSizeMake(photoSize.width * initialZoom,
photoSize.height * initialZoom)];
// Center the photo. Again we push the center point up by 44 pixels
// to account for the translucent navigation bar.
CGPoint scrollCenter = [scrollView center];
[imageView setCenter:CGPointMake(scrollCenter.x,
scrollCenter.y - 44.0)];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[[self navigationController] navigationBar] setBarStyle:UIBarStyleBlackTranslucent];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[[self navigationController] navigationBar] setBarStyle:UIBarStyleDefault];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return imageView;
}
@end
그 setZoomScale 호출이 무엇을? 내 ZoomScrollView를 사용하고 있습니까? –