zoukankan      html  css  js  c++  java
  • UIScrollView

    scroll view 例子:

    //
    //  RootViewController.m
    //  testView
    //
    //  Created by lishujun on 14-9-20.
    //  Copyright (c) 2014年 lishujun. All rights reserved.
    //
    
    #import "RootViewController.h"
    
    @implementation RootViewController
    @synthesize scrollView;
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        
        scrollView = [[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
        [self.view addSubview:scrollView];
        
        scrollView.backgroundColor = [UIColor redColor];
        scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * 2, scrollView.frame.size.height);
        scrollView.pagingEnabled = YES;
        scrollView.showsHorizontalScrollIndicator = YES;
        scrollView.delegate = self;
        
        CGRect rect = [[UIScreen mainScreen]bounds];
        NSArray *colors = [NSArray arrayWithObjects:[UIColor yellowColor], [UIColor blueColor], nil];
        
        for (int i = 0; i < 2; i++) {
            
            CGRect aRect = CGRectMake(rect.origin.x + (i * rect.size.width), rect.origin.y,
                                      rect.size.width, rect.size.height);
            UIView *view1 = [[UIView alloc]initWithFrame:aRect];
            view1.backgroundColor = colors[i];
            [scrollView addSubview:view1];
        }
    }
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        // 拖拽过程调用
    }
    
    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
    {
        // 拖拽完毕以后调用
        int index = [self getPageIndex:scrollView];
        NSLog(@"index = %d",index);
    }
    
    -(int) getPageIndex:(UIScrollView *)scrollView
    {
        return fabs(scrollView.contentOffset.x) /  scrollView.frame.size.width;
    }
    
    @end
  • 相关阅读:
    P3015 [USACO11FEB]最好的括号Best Parenthesis
    P1944 最长括号匹配_NOI导刊2009提高(1)
    P2328 [SCOI2005]超级格雷码
    P2308 添加括号
    P5657 格雷码【民间数据】
    P2196 挖地雷
    P5020 货币系统
    括号序列模型--序列dp--U86873 小Y的精灵国机房之旅
    P1033 自由落体
    P1017 进制转换
  • 原文地址:https://www.cnblogs.com/code-style/p/3984133.html
Copyright © 2011-2022 走看看