目标C的例子寻求

时间:2010-01-14 18:47:00

标签: objective-c macos scrollbars ikimageview

我正在尝试将滚动条添加到IKImageView。基本上目前,我需要一些程序示例将图像加载到视图中,如果窗口太小,设置滚动条可以做正确的事情......

为什么我在apple dev网站上找不到这些例子?

添加信息:

在查看ImagekitDemo后,我发现显然我需要将IKIMageView嵌入ScrollView中。 (并以某种方式使IKImageView的has___Scroller属性为...)

然而,现在(在ImageKitDemo中也是如此)只要只需要一个(或两者都不需要),滚动条就可以了。但是,只要两者都需要,并且窗口的任何一个尺寸都小于图像,两个滚动条就会消失。

鼠标滚动仍然有效。

2 个答案:

答案 0 :(得分:0)

最好的起点是Scroll View Programming Guide。基本上,您需要将IKImageView放在NSScrollView中。如果IKImageView大小超过NSScrollView的可见矩形,则会出现滚动条。

以下sample uses IKImageView执行各种缩放和调整大小操作。

答案 1 :(得分:0)

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