2010-01-14 60 views
5

我試圖將滾動條添加到IKImageView。現在基本上,我需要一些將圖像加載到視圖中的程序示例,如果窗口太小,則會設置滾動條來執行正確的操作...Objective C搜索示例

爲什麼我找不到這些示例在蘋果開發網站?

新增信息:

看着ImagekitDemo後,我看到,顯然我需要嵌入IKIMageView在滾動型。 (並以某種方式使IKImageView的has___Scroller屬性爲...)

但是,現在(ImageKitDemo也是如此)只要只有一個(或兩者都不需要)滾動條就沒問題。但是,只要兩者都需要,窗口的任一維度都小於圖像,則兩個滾動條消失。

鼠標滾動仍然有效。

+0

請參閱我的回答你的[其它問題](http://stackoverflow.com/questions/2060614)。 – 2010-01-24 20:55:20

回答

0

最好的地方是Scroll View Programming Guide。基本上,您需要將IKImageView放入NSScrollView中。如果IKImageView大小超過NSScrollView的可見矩形,則會出現滾動條。

以下sample uses IKImageView執行各種縮放和調整大小操作。

+0

即使IKImageView聲明有滾動條本身? 此外,當我這樣做時,圖像被集中在巨大的圖像視圖中,所以只有它的一部分是可見的...而當imageview小於scrollview時,最終會出現白色背景。我想我可以做一個正常的事情,使imageview的圖像的大小,並在它後面有另一個灰色視圖...但這種失敗了一些ikimageview的目的... – 2010-01-15 14:50:19

+0

我道歉,我閱讀文檔太快了。 「zoomImageTo ...」用於改變圖像矩形,從而改變IKImageView中的可見部分。有一些屬性控制滾動條是否可見。此外,你可以看看下面的示例代碼:http://developer.apple.com/mac/library/samplecode/IKImageViewDemo/index.html – 2010-01-15 15:58:05

+0

是的,我試過改變屬性,但[_imageView setHasHorizo​​ntalScroller:YES]沒有效果([_imageView hasHorizo​​ntalScroller]直接返回0)這個例子是我一直在努力。它似乎展示瞭如何做一切,但滾動條B-) – 2010-01-15 16:35:31

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 
+0

是啊,我已經滾動條與NSView一起工作,但這不會縮放和旋轉和裁剪我...我想要IKImageView以工作... – 2010-01-21 14:35:20

+0

對不起,我有大腦的iPhone和誤讀的問題 – slf 2010-01-21 16:20:30