zoukankan      html  css  js  c++  java
  • ScrollView&PageControl

     1 //
     2 //  ViewController.m
     3 //  分屏导航
     4 //
     5 //  Created by wky on 15/10/2017.
     6 //  Copyright © 2017 vector. All rights reserved.
     7 //
     8 
     9 #import "ViewController.h"
    10 
    11 @interface ViewController ()
    12 @property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
    13 @property (weak, nonatomic) IBOutlet UIPageControl *pageControl;
    14 
    15 
    16 - (IBAction)changePage:(id)sender;
    17 
    18 @property (strong,nonatomic) UIImageView* imageView1;
    19 @property (strong,nonatomic) UIImageView* imageView2;
    20 @property (strong,nonatomic) UIImageView* imageView3;
    21 
    22 @end
    23 
    24 @implementation ViewController
    25 
    26 - (void)viewDidLoad {
    27     [super viewDidLoad];
    28     // Do any additional setup after loading the view, typically from a nib.
    29     
    30     self.scrollView.delegate = self;
    31     
    32     self.scrollView.frame = self.view.frame;
    33     
    34     CGFloat width = self.view.frame.size.width;
    35     
    36     CGFloat height = self.view.frame.size.height;
    37     
    38     self.scrollView.contentSize = CGSizeMake(width*3,height);
    39     
    40     
    41     //1
    42     self.imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,320,480)];
    43     
    44     self.imageView1.image = [UIImage imageNamed:@"1.png"];
    45     
    46     [self.scrollView addSubview:self.imageView1];
    47     
    48     //2
    49     self.imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(320,0,320,480)];
    50     
    51     self.imageView2.image = [UIImage imageNamed:@"2.png"];
    52     
    53     [self.scrollView addSubview:self.imageView2];
    54 
    55     //3
    56     self.imageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(320*2,0,320,480)];
    57     
    58     self.imageView3.image = [UIImage imageNamed:@"3.png"];
    59     
    60     [self.scrollView addSubview:self.imageView3];
    61     
    62    
    63 
    64     
    65     
    66 }
    67 //在头文件中继承一下UIScrollViewDelegate
    68 -(void) scrollViewDidScroll:(UIScrollView *)scrollView
    69 {
    70     CGPoint offset = scrollView.contentOffset;
    71     
    72     self.pageControl.currentPage= offset.x/320;
    73     
    74 }
    75 
    76 
    77 
    78 
    79 - (void)didReceiveMemoryWarning {
    80     [super didReceiveMemoryWarning];
    81     // Dispose of any resources that can be recreated.
    82 }
    83 
    84 
    85 - (IBAction)changePage:(id)sender {
    86     
    87     [UIView animateWithDuration:0.3f animations:^{
    88         NSInteger whichPage = self.pageControl.currentPage;
    89         self.scrollView.contentOffset = CGPointMake(320*whichPage, 0);
    90     }];
    91     
    92     
    93 }
    94 @end
  • 相关阅读:
    sicily 山海经 线段树实例
    常用位运算
    广度优先搜索有环图
    线性O(N)时间复杂度求素数 , 筛法
    sicily2014
    机器学习中相似性度量(转载)
    VS2010中Parallel的使用
    CKeditor与Asp.net验证控件的问题
    将div一直保持到页面底部
    利用DataAnnotations验证实体(类)的属性
  • 原文地址:https://www.cnblogs.com/vector11248/p/7674490.html
Copyright © 2011-2022 走看看