zoukankan      html  css  js  c++  java
  • UI 运用滚动视图创建相册的方法

      1 #import "mainViewController.h"
      2 
      3 
      4 @interface mainViewController ()
      5 
      6 
      7 @end
      8 
      9 
     10 @implementation mainViewController
     11 
     12 
     13 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
     14 
     15 {
     16 
     17     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
     18 
     19     if (self) {
     20 
     21         // Custom initialization
     22 
     23     }
     24 
     25     return self;
     26 
     27 }
     28 
     29 
     30 - (void)viewDidLoad
     31 
     32 {
     33 
     34     [super viewDidLoad];
     35 
     36     // Do any additional setup after loading the view.
     37 
     38    //总的
     39 
     40     UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 20, 280, 450)];
     41 
     42     scrollView.backgroundColor = [UIColor redColor];
     43 
     44     scrollView.tag = 1000;
     45 
     46     scrollView.contentSize = CGSizeMake(1400, 0);
     47 
     48     scrollView.scrollEnabled = YES;
     49 
     50     scrollView.pagingEnabled = YES;
     51 
     52     //第一个
     53 
     54     UIScrollView *scrollView1 = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 20, 240, 450)];
     55 
     56     scrollView1.contentSize = CGSizeMake(240, 0);
     57 
     58     scrollView1.tag = 111;
     59 
     60     UIImageView *image0 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 240, 400)];
     61 
     62     image0.image = [UIImage imageNamed:@"1.JPG"];
     63 
     64     [scrollView1 addSubview:image0];
     65 
     66     [image0 release];
     67 
     68     scrollView1.delegate = self;
     69 
     70     scrollView1.minimumZoomScale = 0.5;
     71 
     72     scrollView1.maximumZoomScale = 2;
     73 
     74     [scrollView addSubview:scrollView1];
     75 
     76     [scrollView1 release];
     77 
     78     //第二个
     79 
     80     UIScrollView *scrollView2 = [[UIScrollView alloc] initWithFrame:CGRectMake(300, 20, 240, 450)];
     81 
     82     scrollView2.contentSize = CGSizeMake(280, 0);
     83 
     84     scrollView2.tag = 222;
     85 
     86     UIImageView *image1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 240, 400)];
     87 
     88     image1.image = [UIImage imageNamed:@"2.JPG"];
     89 
     90     [scrollView2 addSubview:image1];
     91 
     92     [image1 release];
     93 
     94     
     95 
     96     scrollView2.delegate = self;
     97 
     98     scrollView2.minimumZoomScale = 0.5;
     99 
    100     scrollView2.maximumZoomScale = 2;
    101 
    102     [scrollView addSubview:scrollView2];
    103 
    104     [scrollView2 release];
    105 
    106     //第三个
    107 
    108     UIScrollView *scrollView3 = [[UIScrollView alloc] initWithFrame:CGRectMake(580, 20, 240, 450)];
    109 
    110     scrollView3.contentSize = CGSizeMake(280, 0);
    111 
    112     scrollView3.tag = 333;
    113 
    114     UIImageView *image2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 240, 400)];
    115 
    116     image2.image = [UIImage imageNamed:@"3.JPG"];
    117 
    118     [scrollView3 addSubview:image2];
    119 
    120     [image2 release];
    121 
    122 
    123     scrollView3.delegate = self;
    124 
    125     scrollView3.minimumZoomScale = 0.5;
    126 
    127     scrollView3.maximumZoomScale = 2;
    128 
    129     [scrollView addSubview:scrollView3];
    130 
    131     [scrollView3 release];
    132 
    133     //第四个
    134 
    135     UIScrollView *scrollView4 = [[UIScrollView alloc] initWithFrame:CGRectMake(860, 20, 240, 450)];
    136 
    137     scrollView4.contentSize = CGSizeMake(280, 0);
    138 
    139     scrollView4.tag = 444;
    140 
    141     UIImageView *image3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 240, 400)];
    142 
    143     image3.image = [UIImage imageNamed:@"4.JPG"];
    144 
    145     [scrollView4 addSubview:image3];
    146 
    147     [image3 release];
    148 
    149     scrollView4.delegate = self;
    150 
    151     scrollView4.minimumZoomScale = 0.5;
    152 
    153     scrollView4.maximumZoomScale = 2;
    154 
    155     [scrollView addSubview:scrollView4];
    156 
    157     [scrollView4 release];
    158 
    159     //第五个
    160 
    161     UIScrollView *scrollView5 = [[UIScrollView alloc] initWithFrame:CGRectMake(1140, 20, 240, 450)];
    162 
    163     scrollView5.contentSize = CGSizeMake(280, 0);
    164 
    165     scrollView5.tag = 555;
    166 
    167     UIImageView *image4 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 240, 400)];
    168 
    169     image4.image = [UIImage imageNamed:@"5.JPG"];
    170 
    171     [scrollView5 addSubview:image4];
    172 
    173     [image4 release];
    174 
    175     scrollView5.delegate = self;
    176 
    177     scrollView5.minimumZoomScale = 0.5;
    178 
    179     scrollView5.maximumZoomScale = 2;
    180 
    181     [scrollView addSubview:scrollView5];
    182 
    183     [scrollView5 release];
    184 
    185 
    186     scrollView.delegate = self;
    187 
    188     [self.view addSubview:scrollView];
    189 
    190     [scrollView release];
    191 
    192     
    193 
    194     UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(110, 400, 100,30)];
    195 
    196     pageControl.numberOfPages = 5;
    197 
    198     pageControl.pageIndicatorTintColor = [UIColor blackColor];
    199 
    200     pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    201 
    202     [pageControl addTarget:self action:@selector(pageControlAction:)forControlEvents:UIControlEventValueChanged];
    203 
    204     [self.view addSubview:pageControl];
    205 
    206     [pageControl release];
    207 
    208     
    209 
    210     self.page = pageControl;
    211 
    212     
    213 
    214     
    215 
    216 }
    217 
    218 - (void)pageControlAction:(UIPageControl *)pageControl
    219 
    220 {
    221 
    222     UIScrollView *scrollView = (UIScrollView *) [self.view viewWithTag:1000];
    223 
    224     scrollView.contentOffset = CGPointMake(280 * self.page.currentPage, 0);
    225 
    226     for (int i = 1; i < 6; i++) {
    227 
    228         UIScrollView *scrollView = (UIScrollView *) [self.view viewWithTag:111 * i];
    229 
    230         scrollView.zoomScale = 1;
    231 
    232     }
    233 
    234 }
    235 
    236 - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    237 
    238 {
    239 
    240     self.page.currentPage = scrollView.contentOffset.x / scrollView.frame.size.width;
    241 
    242 }
    243 
    244 
    245 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
    246 
    247 {
    248 
    249     return [scrollView.subviews firstObject];
    250 
    251 }
    252 
    253 
    254 - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
    255 
    256 {
    257 
    258     for (int i = 1; i < 6; i ++) {
    259 
    260         UIScrollView *scrollView = (UIScrollView *) [self.view viewWithTag:111 * i];
    261 
    262         scrollView.zoomScale = 1;
    263 
    264     }
    265 
    266 }
    267 
    268 
    269 - (void)didReceiveMemoryWarning
    270 
    271 {
    272 
    273     [super didReceiveMemoryWarning];
    274 
    275     // Dispose of any resources that can be recreated.
    276 
    277 }
    278 
    279 
    280 /*
    281 
    282 #pragma mark - Navigation
    283 
    284 
    285 // In a storyboard-based application, you will often want to do a little preparation before navigation
    286 
    287 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    288 
    289 {
    290 
    291     // Get the new view controller using [segue destinationViewController].
    292 
    293     // Pass the selected object to the new view controller.
    294 
    295 }
    296 
    297 */
    298 
    299 
    300 @end
    有人说:爱上一座城,是因为城里住着某个人,能够与所爱的人在一起,连光阴都是美的。即便粗茶淡饭,修篱种田,只要有你陪伴就好。那么,找一个青山绿水的地方,寻一处幽静的茅舍,或是云水禅心的庭院,那里有晴朗的阳光和静谧的悠然,还有你明媚的笑脸。掬一捧花香在平淡的日子,握着一路相随的暖意,让爱的馨香在柴米油盐中升腾;在一杯茶的温情里,体味生活的诗意;在一碗粥的清淡中,感受生活的浪漫,每天清晨你和阳光都在,便是我的幸福。——春暖花开 《择一城终老,遇一人白首》
  • 相关阅读:
    kali长时间未使用导致数字签名过期无法更新源解决办法
    4.爬虫去重策略
    3.编码问题
    kalinux 五笔安装
    ★★★kalinux 常用命令
    安装vm tools时出现如下问题 The path "/usr/bin/gcc" is not valid path to the
    kalinux实现自适用全屏、与物理主机共享文件方法
    wifi pj WiFiPhisher 安装使用
    条款20:在传递对象的时候尽量用reference-to-constent来代替,pass-by-value
    条款19:定义class就相当于定义一个个的内置类型
  • 原文地址:https://www.cnblogs.com/-Eric-Liu/p/5563951.html
Copyright © 2011-2022 走看看