5

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

为什么我在苹果开发网站上找不到这些示例?

添加信息:

在查看 ImagekitDemo 之后,我发现显然我确实需要将 IKIMageView 嵌入到 ScrollView 中。(不知何故,这使得 IKImageView 的 has___Scroller 属性为 YES ......)

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

鼠标滚动仍然有效。

4

2 回答 2

0

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

以下示例使用 IKImageView执行各种缩放和调整大小操作。

于 2010-01-15T08:31:04.063 回答
0

缩放视图控制器.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

缩放视图控制器.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
于 2010-01-21T13:23:32.223 回答