久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在滾動視圖內的 UIImageView 上捏縮放效果?

Pinch To Zoom Effect on UIImageView inside scrollView?(在滾動視圖內的 UIImageView 上捏縮放效果?)
本文介紹了在滾動視圖內的 UIImageView 上捏縮放效果?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用情節提要 (iOS 6.0) 為我的應用創建照片庫查看器.這就是我的 imageViewController 在情節提要中的設置方式:

I'm using storyboard (iOS 6.0) to create a photo gallery viewer for my app. This is how my imageViewController is set up in storyboard:

我已確保在 imageView 和 scrollView 上啟用 userInteraction 和多次觸摸.我想要做的是,在捏我想放大 imageView(最大比例 3)并能夠平移.這是我目前擁有的,但是,即使檢測到捏合手勢,比例也不會改變.

I've made sure to enable userInteraction and multiple touches on both the imageView and scrollView. What I want to do is, on pinch I want to zoom into the imageView (maximum scale 3) and be able to pan around. This is what I currently have, however, even though the pinch gesture is detected the scale does not change.

- (IBAction)imagePinched:(id)sender {

if (pinchRecognizer.state == UIGestureRecognizerStateEnded || pinchRecognizer.state == UIGestureRecognizerStateChanged) {

    NSLog(@"gesture.scale = %f", pinchRecognizer.scale);

    CGFloat currentScale = self.fullScreenView.frame.size.width / self.fullScreenView.bounds.size.width;
    CGFloat newScale = currentScale * pinchRecognizer.scale;

    if (newScale < 1) {
        newScale = 1;
    }
    if (newScale > 3) {
        newScale = 3;
    }

    CGAffineTransform transform = CGAffineTransformMakeScale(newScale, newScale);
        self.fullScreenView.transform = transform;
        pinchRecognizer.scale = 1;
    }

}

大多數在線問題和教程都涉及以編程方式創建視圖并執行此操作,但代碼越少越好(在我看來).讓它與故事板一起使用的最佳方法是什么?提前謝謝!!!

Most questions and tutorials online deal with programmatically creating the views and doing this, but the less code the better (in my eyes). What's the best way to get this to work with storyboard? Thank you in advance!!!

更新:

這是我完整的 .m 文件代碼:

Here is my full .m file code:

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Assign an image to this controller's imageView
    fullScreenView.image = [UIImage imageNamed:imageString];

    //Allows single and double tap to work
    [singleTapRecognizer requireGestureRecognizerToFail: doubleTapRecognizer];
}

- (IBAction)imageTapped:(id)sender {

    NSLog(@"Image Tapped.");

    //On tap, fade out viewController like the twitter.app
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)imageDoubleTapped:(id)sender {

    NSLog(@"Image Double Tapped.");

    //On double tap zoom into imageView to fill in the screen.
    [fullScreenView setContentMode:UIViewContentModeScaleAspectFill];
}

- (IBAction)imagePinched:(id)sender {

    if (pinchRecognizer.state == UIGestureRecognizerStateEnded || pinchRecognizer.state == UIGestureRecognizerStateChanged) {

        NSLog(@"gesture.scale = %f", pinchRecognizer.scale);

        CGFloat currentScale = self.fullScreenView.frame.size.width / self.fullScreenView.bounds.size.width;
        CGFloat newScale = currentScale * pinchRecognizer.scale;

        if (newScale < 1) {
            newScale = 1;
        }
        if (newScale > 3) {
            newScale = 3;
        }

        CGAffineTransform transform = CGAffineTransformMakeScale(newScale, newScale);
        self.fullScreenView.transform = transform;
        pinchRecognizer.scale = 1;
    }
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.fullScreenView;
}


-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

推薦答案

我認為 Apple 文檔中有更好的解決方案

I think better solution in Apple Documentation

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

{

    return self.imageView;

}
- (void)viewDidLoad {

    [super viewDidLoad];

    self.scrollView.minimumZoomScale=0.5;

    self.scrollView.maximumZoomScale=6.0;

    self.scrollView.contentSize=CGSizeMake(1280, 960);

    self.scrollView.delegate=self;

}

查看 Apple 文檔

這篇關于在滾動視圖內的 UIImageView 上捏縮放效果?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點擊手勢獲取索引或標簽值)
UIScrollView not scrolling regardless of large contentSize(無論內容大小如何,UIScrollView 都不會滾動)
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動旋轉轉換)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動布局縮放)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創建圖像)
主站蜘蛛池模板: 国产欧美在线 | www.日本高清 | 一级片在线观看视频 | 高潮毛片无遮挡免费看 | 日本成人中文字幕 | 在线视频91 | 日本精品免费 | 日韩在线免费 | 欧美成人猛片aaaaaaa | 亚洲成人免费网站 | 中文有码在线 | 日韩在线视频观看 | 亚洲免费二区 | 麻豆视频国产 | 九九视频这里只有精品 | 一级片免费观看 | 亚洲精品自拍视频 | 香蕉久久a毛片 | 一区二区高清 | 四虎影库 | 成年网站在线观看 | 欧美日韩一二三区 | 国产h在线观看 | 欧美精品99 | 伊人网在线| 日韩中文字幕一区二区 | 激情五月激情综合网 | 婷婷导航| av噜噜噜 | 欧美一区二区三区免费 | www久久| 日日干干 | 亚洲激情一区 | 亚洲123区| 欧美日韩中文 | 五月婷丁香 | 亚洲图片一区二区 | 欧美福利视频 | 中文字幕在线观看日本 | 日韩伦理一区 | 亚洲黄色在线视频 |