2012-03-07 84 views
1

我有頁面UIScrollView與圖像。我想在一些手勢上實現圖像動畫縮放到全屏。另一個動畫可以將圖像縮放回滾動視圖。就像iPad上的照片應用程序或Safari中的視頻一樣。如何將圖像縮放到全屏模式?

當然它不會是UIImageView。這將是一些包裝裏面的包裝類。主要問題是如何呈現全屏視圖。它是否必須是模態視圖?

任何幫助表示讚賞。

回答

6

檢查觸摸圖像 如果有進一步的說明小轉換成全尺寸。如果它很大,則將其轉換成小尺寸。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    if (isLarge) [self makeSmall]; 
    else [self makeFull]; 
} 

- (void)makeFull { 
    [[self superview] bringSubviewToFront:self]; 
    isLarge = YES; 
    CGRect largeFrame = [self superview].bounds; 
    original = self.frame; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [self setFrame:largeFrame]; 
    [internal setFrame:self.bounds]; 
    [UIView commitAnimations]; 

} 
- (void)makeSmall { 
    isLarge = NO; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [self setFrame:original]; 
    [internal setFrame:self.bounds]; 
    [UIView commitAnimations]; 

} 
+0

對我來說效果不好。我的滾動視圖不是全屏。它位於設計屏幕上的小區域。我需要使用圖像查看來覆蓋所有其他視圖並變爲全屏。 – Lloyd18 2012-03-07 14:41:12

+0

感謝你的幫助,我在一個緊要關頭;) – Madoc 2012-06-21 09:55:35

+0

感謝Kothari bhai ..這也幫助了我..以及aur kaisi cahl rahi hai TCS ..? – 2012-10-29 08:47:27

2

下載這個sample的圖片庫示例代碼,並通過它。它肯定會幫助你理解如何實現你的想法。

+0

我們要查看代碼,而不是下載樣本... – cvsguimaraes 2013-09-05 13:22:16

+2

不要這麼貪心。樣本非常有教育意義。我總是從他們身上學到一些東西,即使這與我的搜索無關。 – FrostyL 2013-11-16 06:43:43

1

像下面一樣,您可以使用縮放圖像視圖。

UIView * viewForScroll; 

UIImageView *imgviewForScroll; 

UIScrollView *scrollToRead = [[UIScrollViewalloc]initWithFrame:CGRectMake(175, 5, 300, 311)]; 

scrollToRead.backgroundColor = [UIColordarkGrayColor]; 

scrollToRead.showsHorizontalScrollIndicator = YES; 

scrollToRead.delegate = self; 

[scrollToRead setContentSize:CGRectMake(0, 0, 300, 400).size]; 

scrollToRead.maximumZoomScale = 2; 

scrollToRead.minimumZoomScale = 1; 

[self.view addSubview:scrollToRead]; 

[scrollToRead release]; 

viewForScroll = [[UIViewalloc]initWithFrame:CGRectMake(0,0,300,400)]; 

[scrollToRead addSubview:viewForScroll]; 

[viewForScroll release]; 

imgviewForScroll = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,300,400)]; 

imgviewForScroll.image = [UIImageimageWithContentsOfFile:[arrayComicContentobjectAtIndex:0]]; 

[viewForScroll addSubview:imgviewForScroll]; 

[imgviewForScroll release]; 

// ========= UIScrollView的委託方法

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { 


    return viewForScroll; 
    } 

想知道,如果你需要

+0

hm ..這種方法不適合我。我需要圖像成爲全屏和HM ...像模態。在你的情況下,它只是放大滾動視圖。我neen滾動視圖保持原樣,而縮放。只有圖像必須縮放並覆蓋後面的滾動視圖。 – Lloyd18 2012-03-07 11:01:02

3

我找到了一個涉及手勢識別器和動畫過渡的解決方案。您刪除滾動視圖並添加全屏圖像。然後反轉,返回到正確的滾動視圖。

使用窗口的框架來確定新的UIImage的大小。

可以調整手勢識別器的類型以滿足您的需求!

-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    UITapGestureRecognizer *tapTwice = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwice:)]; 
    tapTwice.numberOfTapsRequired = 2; 
    [self.imageView addGestureRecognizer:tapTwice]; 
} 

- (void)tapOnce:(id)tapOnce { 
    [UIView transitionWithView:self.view 
        duration:0.7 
        options:UIViewAnimationOptionTransitionCrossDissolve 
       animations:^ { 
        [self.fullScreenImage removeFromSuperview]; 
       } 
       completion:nil]; 
} 

- (void)tapTwice:(id)tapTwice { 
    if(self.fullScreenImage == nil){ 
     self.fullScreenImage = [[UIImageView alloc] initWithFrame:self.view.window.frame]; 

     UITapGestureRecognizer *tapOnce = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnce:)]; 
     tapOnce.numberOfTapsRequired = 1; 
     [tapOnce requireGestureRecognizerToFail:tapTwice]; 
     [self.fullScreenImage addGestureRecognizer:tapOnce]; 
     [self.fullScreenImage setUserInteractionEnabled:YES]; 

     //self.fullScreenImage = [load your image here] 
    } 

    [UIView transitionWithView:self.view.window 
         duration:0.7 
         options:UIViewAnimationOptionTransitionCrossDissolve 
        animations:^ { 
         [self.view.window addSubview:self.fullScreenImage]; 
        } 
        completion:nil]; 
}