2012-03-07 83 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]; 
}