欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS 點(diǎn)擊圖片放大效果的實(shí)現(xiàn)

 更新時(shí)間:2017年01月09日 11:34:36   作者:Amydom  
本篇文章主要介紹了iOS 點(diǎn)擊圖片放大效果的實(shí)現(xiàn),這種效果一般在微博,微信朋友圈中比較常見,有興趣的可以了解一下。

今天帶來的是圖片點(diǎn)擊放大效果,這種效果一般在微博,微信朋友圈中比較常見

當(dāng)我點(diǎn)擊其中一張圖片時(shí),就會(huì)進(jìn)入詳情

具體實(shí)現(xiàn)如下

首先創(chuàng)建個(gè) Controller(PhotoViewController)

// 
// PhotoViewController.h 
// 點(diǎn)擊圖片放大效果 
// 
// Created by Amydom on 17/1/9. 
// Copyright © 2017年 Amydom. All rights reserved. 
// 
 
#import <UIKit/UIKit.h> 
 
@interface PhotoViewController : UIViewController 
 
//保存圖片的數(shù)組 
@property (nonatomic, strong)NSMutableArray *photoArr; 
//圖片 tag 
@property (nonatomic, assign)NSInteger imageTag; 
 
@end 
// 
// PhotoViewController.m 
// 點(diǎn)擊圖片放大效果 
// 
// Created by Amydom on 17/1/9. 
// Copyright © 2017年 Amydom. All rights reserved. 
// 
 
#import "PhotoViewController.h" 
 
@interface PhotoViewController () 
 
@end 
 
@implementation PhotoViewController 
 
- (void)viewDidLoad { 
  [super viewDidLoad]; 
   
  UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)]; 
   
  myScrollView.backgroundColor = [UIColor blackColor]; 
  myScrollView.pagingEnabled = YES; 
  myScrollView.bounces = NO; 
   
  [self.view addSubview:myScrollView]; 
  //根據(jù)tag 來獲取當(dāng)前點(diǎn)擊的圖片 
  myScrollView.contentOffset = CGPointMake(self.view.frame.size.width * self.imageTag, 10); 
   
  myScrollView.contentSize = CGSizeMake(self.view.frame.size.width * self.photoArr.count, 667); 
  //創(chuàng)建 
  for (int i = 0; i < self.photoArr.count; i++) 
  { 
    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * i + 10, 0, self.view.frame.size.width - 20, self.view.frame.size.height)]; 
    NSString *imgName = self.photoArr[i]; 
    img.image = [UIImage imageNamed:imgName]; 
     
    [myScrollView addSubview:img]; 
     
    //自適應(yīng)圖片大小 
    img.contentMode = UIViewContentModeScaleAspectFit; 
     
  } 
   
  //輕拍跳出照片瀏覽 
  UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)]; 
   
  [myScrollView addGestureRecognizer:tap]; 
 
} 
 
- (void)tapAction 
{ 
  [self dismissViewControllerAnimated:YES completion:^{ 
     
     
  }]; 
} 
 
- (void)didReceiveMemoryWarning { 
  [super didReceiveMemoryWarning]; 
  // Dispose of any resources that can be recreated. 
} 
 
/* 
#pragma mark - Navigation 
 
// In a storyboard-based application, you will often want to do a little preparation before navigation 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
  // Get the new view controller using [segue destinationViewController]. 
  // Pass the selected object to the new view controller. 
} 
*/ 
 
@end 

然后在 ViewController 中創(chuàng)建四張小圖片,添加輕拍手勢(shì)

// 
// ViewController.m 
// 點(diǎn)擊圖片放大效果 
// 
// Created by Amydom on 17/1/9. 
// Copyright © 2017年 Amydom. All rights reserved. 
// 
 
#import "ViewController.h" 
#import "PhotoViewController.h" 
 
@interface ViewController (){ 
   
  NSMutableArray *array; 
   
} 
 
@end 
 
@implementation ViewController 
 
- (void)viewDidLoad { 
  [super viewDidLoad]; 
  self.view.backgroundColor = [UIColor whiteColor]; 
  array = [NSMutableArray arrayWithObjects:@"1.jpg", @"2.jpg",@"3.jpg",@"4.jpg", nil nil]; 
  for (int i = 0; i < array.count; i++) { 
     
    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(20 + 880 * i, 100, 70, 70)]; 
    img.image = [UIImage imageNamed:[array objectAtIndex:i]]; 
     
    img.userInteractionEnabled = YES; 
     
    //截掉邊框 
    img.clipsToBounds = YES; 
     
    img.tag = 1000 + i; 
     
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(TapAction:)]; 
     
    [img addGestureRecognizer:tap]; 
     
    [self.view addSubview:img]; 
  } 
 
} 
 
- (void)TapAction:(UITapGestureRecognizer *)tap{ 
   
  PhotoViewController *photoVC = [[PhotoViewController alloc] init]; 
  photoVC.imageTag = tap.view.tag - 1000 ;//獲取當(dāng)前被點(diǎn)擊圖片的 tag 
  photoVC.photoArr = array; 
  [photoVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];// 效果 
  [self presentModalViewController:photoVC animated:YES]; 
   
} 
- (void)didReceiveMemoryWarning { 
  [super didReceiveMemoryWarning]; 
  // Dispose of any resources that can be recreated. 
} 
 
 
@end 

這樣就可以實(shí)現(xiàn)啦........當(dāng)然這里只是單純的實(shí)現(xiàn)功能,至于想要圖片循環(huán)什么的還是需要根據(jù)需求自行添加..

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • ios開發(fā) try-catch引起的野指針問題排查

    ios開發(fā) try-catch引起的野指針問題排查

    這篇文章主要為大家介紹了ios開發(fā) try-catch引起的野指針問題排查,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • IOS 中NSTimer定時(shí)器的使用

    IOS 中NSTimer定時(shí)器的使用

    這篇文章主要介紹了IOS 中NSTimer定時(shí)器的使用的相關(guān)資料,希望通過本文能幫助到大家,能讓大家徹底理解使用該方法,需要的朋友可以參考下
    2017-10-10
  • IOS開發(fā)代碼分享之獲取啟動(dòng)畫面圖片的string

    IOS開發(fā)代碼分享之獲取啟動(dòng)畫面圖片的string

    本文是IOS開發(fā)代碼分享系列的第一篇文章,這里分享下獲取啟動(dòng)畫面圖片的string的代碼,本代碼支持 iPhone 6 以下. 支持 iPhone 及 iPad,非常實(shí)用,希望對(duì)大家有所幫助
    2014-09-09
  • IOS 常見的循環(huán)引用總結(jié)

    IOS 常見的循環(huán)引用總結(jié)

    這篇文章主要介紹了IOS 常見的循環(huán)引用總結(jié)的相關(guān)資料,循環(huán)引用,指的是多個(gè)對(duì)象相互引用時(shí),使得引用形成一個(gè)環(huán)形,導(dǎo)致外部無法真正是否掉這塊環(huán)形內(nèi)存。其實(shí)有點(diǎn)類似死鎖,需要的朋友可以參考下
    2017-03-03
  • iOS長按UIlabel實(shí)現(xiàn)可復(fù)制功能

    iOS長按UIlabel實(shí)現(xiàn)可復(fù)制功能

    在我們?nèi)粘5拈_發(fā)中經(jīng)常會(huì)遇到一些小需求,比如需要長按控件來拷貝控件中得內(nèi)容,所以這篇文章跟大家分享下iOS中長按UIlabel實(shí)現(xiàn)可復(fù)制功能的方法,有需要的朋友們可以參考借鑒。
    2016-09-09
  • iOS如何將圖片裁剪成圓形

    iOS如何將圖片裁剪成圓形

    這篇文章主要為大家詳細(xì)介紹了iOS如何將圖片裁剪成圓形,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • IOS 開發(fā)之xcode對(duì)比兩個(gè)分支中同一個(gè)文件

    IOS 開發(fā)之xcode對(duì)比兩個(gè)分支中同一個(gè)文件

    這篇文章主要介紹了IOS 開發(fā)之xcode對(duì)比兩個(gè)分支中同一個(gè)文件的相關(guān)資料,希望通過本文能幫助到大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下
    2017-08-08
  • iOS 實(shí)現(xiàn)跑馬燈效果的方法示例

    iOS 實(shí)現(xiàn)跑馬燈效果的方法示例

    可能說起跑馬燈,大家第一個(gè)會(huì)想到的就是山寨機(jī)。但接下來這篇文章介紹的跑馬燈和那個(gè)跑馬燈是不一樣滴。在iOS中,跑馬燈是指label上的字自動(dòng)滾動(dòng),形成類似跑馬燈似的條幅。下面通過這篇文章我們來一起看看iOS 實(shí)現(xiàn)跑馬燈效果的方法,有需要的朋友們可以參考借鑒。
    2017-01-01
  • iOS使用視聽媒體框架AVFoundation實(shí)現(xiàn)照片拍攝

    iOS使用視聽媒體框架AVFoundation實(shí)現(xiàn)照片拍攝

    這篇文章主要為大家詳細(xì)介紹了iOS使用視聽媒體框架AVFoundation實(shí)現(xiàn)照片拍攝,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-04-04
  • IOS代碼筆記之勾選

    IOS代碼筆記之勾選"記住密碼"整體button

    這篇文章主要為大家詳細(xì)介紹了IOS實(shí)現(xiàn)勾選"記住密碼"整體button效果的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-07-07

最新評(píng)論