寻求 Objective C 示例

发布于 2024-08-17 20:40:22 字数 357 浏览 11 评论 0原文

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

为什么我在苹果开发人员上找不到这些示例地点?

添加信息:

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

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

鼠标滚动仍然有效。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梅窗月明清似水 2024-08-24 20:40:22

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

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
睡美人的小仙女 2024-08-24 20:40:22

最好的起点是 滚动视图编程指南。基本上,您需要将 IKImageView 放入 NSScrollView 中。如果 IKImageView 大小超过 NSScrollView 的可见矩形,则会出现滚动条。

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文