views:

647

answers:

4

I'm trying to add scrollbars to an IKImageView. Basically at the moment, I need some examples of a program that loads an image into a view, and if the window is too small, sets up scrollbars that do the right things...

Why can I not find these examples on the apple dev site?

Added info:

After looking at ImagekitDemo I see that evidently I DO need to embed the IKIMageView in a ScrollView. (and somehow that makes the has___Scroller properties of the IKImageView YES...)

However, now (And this is true in ImageKitDemo as well) The scroll bars are fine as long as only one (or neither) is needed. However, as soon as both are needed, and either dimension of the window is smaller than the image, BOTH scrollbars disappear.

Mouse scrolling still works.

A: 

The best place to start is the Scroll View Programming Guide. Basically, you need to put the IKImageView inside a NSScrollView. If the IKImageView size exceeds the visible rectangle of the NSScrollView, then scrollbars will appears.

The following sample uses IKImageView to perform various zoom and resizing operations.

Laurent Etiemble
even though the IKImageView claims that has scrollbars itself?Also, when I do that, the Image gets centered in the huge imageview and so only part of it is visible... and when the imageview is smaller than the scrollview, you end up with white backgrounds. I suppose I CAN do a normal thing with making the imageview the size of the image and have another grey view behind it... but that sort of defeats some of the purpose of the ikimageview...
Brian Postow
My apologies, I read the documentation too quickly. The "zoomImageTo..." are made to change the image rectangle, and thus the visible portion in the IKImageView. There are some properties that controls whether scrollbars are visible or not.Moreover, you can take a look at the following sample code: http://developer.apple.com/mac/library/samplecode/IKImageViewDemo/index.html
Laurent Etiemble
yeah, I've tried altering the properties,but [_imageView setHasHorizontalScroller: YES] has no effect ( [_imageView hasHorizontalScroller] returns 0 directly afterwards) And that example is what I've been working off of. It seems to show how to do everything BUT Scrollbars B-)
Brian Postow
+1  A: 

Hope this helps
http://developer.apple.com/mac/library/samplecode/ImageKitDemo/index.html#//apple_ref/doc/uid/DTS10004371
http://developer.apple.com/Mac/library/documentation/GraphicsImaging/Conceptual/ImageKitProgrammingGuide/ImageViews/ImageViews.html
http://stackoverflow.com/questions/1928356/ikimageview-zooming-controlled-by-an-nsslider

zapping
stage 3 of the imagekit demo looks helpful, it describes putting teh IKIMageVIew in a scrollview even though the ikimageview CLAIMS to have it's own scrollbars. But the display of the scroll bars is ... inconsistent... I think that the imageview is covering them most of the time? The ImageKit docs just say "scrollbars will appear if the window is too small" which they don't... and the SO thread doesn't really say anything about scrollbars which is currently my main problem...
Brian Postow
A: 

ZoomViewController.h

@interface ZoomViewController : UIViewController <UIScrollViewDelegate>
{
    ForecastImage* detailImage; // wrapper class around UIImage (optional - could just be UIImage)

    IBOutlet UIImageView* imageView;
    IBOutlet DoubleTapScrollView* zoomableScrollView;
}

@property (readwrite, nonatomic, retain) ForecastImage* detailImage;

- (IBAction) dismissZoomViewController;

- (UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView;

- (void) scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale;

@end

ZoomViewController.m

@implementation ZoomViewController

@synthesize detailImage;

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated
{
    [imageView setImage:[self.detailImage renderedImage]];

    [zoomableScrollView setContentSize:[[imageView image] size]];
    [zoomableScrollView setMaximumZoomScale:5.0];
    [zoomableScrollView setMinimumZoomScale:0.25];
}

- (void) viewDidAppear:(BOOL)animated
{
    self.navigationItem.title = [SearchService getDisplayName:[self.detailImage forecastArea]];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc
{
    imageView.image = nil;
    self.detailImage = nil;

    [super dealloc];
}

- (IBAction) dismissZoomViewController
{
    [self dismissModalViewControllerAnimated:YES];
}

#pragma mark Pinch-n-Zoom

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return imageView;
}

- (void) scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
    CGSize newSize = CGSizeMake(imageView.image.size.width * scale, imageView.image.size.height * scale);
    [scrollView setContentSize:newSize];
}

@end
slf
Yeah, I've gotten scrollbars to work with an NSView, but that doesn't do zooming and rotation and croppingfor me... I'd like to get IKImageView to work...
Brian Postow
sorry, I have iphone on the brain and misread the question
slf
A: 

Please see my answer in your other question.

Nicholas Riley