【问题标题】:Objective C examples sought寻求的 Objective C 示例
【发布时间】:2010-01-14 18:46:59
【问题描述】:

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

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

添加信息:

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

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

鼠标滚动仍然有效。

【问题讨论】:

标签: objective-c macos scrollbars ikimageview


【解决方案1】:

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

【讨论】:

  • 是的,我已经让滚动条与 NSView 一起使用,但这对我来说不能进行缩放、旋转和裁剪......我想让 IKImageView 工作......跨度>
【解决方案2】:

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

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

【讨论】:

  • 即使 IKImageView 声称它本身有滚动条?另外,当我这样做时,图像会在巨大的图像视图中居中,因此只有一部分是可见的......当图像视图小于滚动视图时,你最终会得到白色背景。我想我可以做一件正常的事情,使 imageview 成为图像的大小,并在它后面有另一个灰色视图......但这有点违背了 ikimageview 的一些目的......
  • 抱歉,我阅读文档太快了。 “zoomImageTo...”用于更改图像矩形,从而更改 IKImageView 中的可见部分。有一些属性控制滚动条是否可见。此外,您可以查看以下示例代码:developer.apple.com/mac/library/samplecode/IKImageViewDemo/…
  • 是的,我试过改变属性,但是 [_imageView setHasHorizo​​ntalScroller: YES] 没有效果([_imageView hasHorizo​​ntalScroller] 之后直接返回 0)这个例子就是我一直在研究的.它似乎展示了如何做所有事情,但滚动条 B-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-19
  • 1970-01-01
  • 1970-01-01
  • 2010-12-08
相关资源
最近更新 更多