Uygulamamda, kullanıcılara Fotoğraf uygulamasında kullanılana benzeyen bir tam ekran fotoğraf görüntüleyici sunmak istiyorum. Bu sadece tek bir fotoğraf içindir ve bu nedenle oldukça basit olmalıdır. Ben sadece kullanıcının bu bir fotoğrafı, yakınlaştırma ve kaydırma kabiliyeti ile görüntüleyebilmesini istiyorum.UIImageView'ı tam ekran UIScrollView içine nasıl yerleştiririm?
Çoğu çalışıyorum. Ve eğer UIImageView'imi ortalamıyorsam, her şey mükemmel davranır. Ancak, UIImageView'ın görüntü yeterince büyütülmüş olduğunda ekranda ortalanmasını gerçekten istiyorum. Kaydırma görünümünün sol üst köşesine yapışmasını istemiyorum.
Bu görünümü ortalamayı denediğimde, dikey kaydırılabilir alanım olması gerekenden daha büyük görünüyor. Bu nedenle, bir kez yakınlaştırdığımda, resmin üstünden yaklaşık 100 piksel kaydırmayı başarabiliyorum. Neyi yanlış yapıyorum?
@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
o setZoomScale çağrı nedir? ZoomScrollView'umu kullanıyor musunuz? –