滚动视图UIScrollView

int i;

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.myScrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];

self.myScrollV.backgroundColor = [UIColor whiteColor];

self.myScrollV.contentSize = CGSizeMake(WIDTH * 4, HEIGHT / 4);

self.myScrollV.delegate = self;

[self.view addSubview:self.myScrollV];

UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT / 4)];

imageV.image = [UIImage imageNamed:@"/Users/scjy/Desktop/UI代码/SecrolView/SecrolView/屏幕快照 2016-03-11 下午12.54.17.png"];

[self.myScrollV addSubview:imageV];

UIImageView *imageV1 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH, 0, WIDTH , HEIGHT / 4)];

imageV1.image = [UIImage imageNamed:@"/Users/scjy/Desktop/UI代码/SecrolView/SecrolView/屏幕快照 2016-03-11 下午12.54.27.png"];

[self.myScrollV addSubview:imageV1];

UIImageView *imageV3 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * 3, 0, WIDTH , HEIGHT / 4)];

imageV3.image = [UIImage imageNamed:@"/Users/scjy/Desktop/UI代码/SecrolView/SecrolView/屏幕快照 2016-03-11 下午12.54.00.png"];

[self.myScrollV addSubview:imageV3];

UIImageView *imageV2 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * 2, 0, WIDTH, HEIGHT / 4)];

imageV2.image = [UIImage imageNamed:@"/Users/scjy/Desktop/UI代码/SecrolView/SecrolView/屏幕快照 2016-03-11 下午12.55.26.png"];

[self.view addSubview:imageV2];

UIImageView *imageV4 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * 4, 0, WIDTH, HEIGHT / 4)];

imageV4.image = [UIImage imageNamed:@"/Users/scjy/Desktop/UI代码/SecrolView/SecrolView/屏幕快照 2016-03-11 下午2.29.19.png"];

[self.view addSubview:imageV4];

self.myScrollV.pagingEnabled = YES;

//影藏滚动条

self.myScrollV.showsHorizontalScrollIndicator = NO;

self.myScrollV.directionalLockEnabled = YES;

[self.myScrollV addSubview:imageV2];

self.page = [[UIPageControl alloc] initWithFrame:CGRectMake(100, HEIGHT / 4 - 50, 200, 40)];

self.page.backgroundColor = [UIColor clearColor];

self.page.numberOfPages = 4;

self.page.currentPage = 0;

[self.view addSubview:self.page];

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

{

if (scrollView.contentOffset.x >= 0 && scrollView.contentOffset.x <=  WIDTH * 3)

{

self.page.currentPage =(int)(scrollView.contentOffset.x / WIDTH);

}

else if (scrollView.contentOffset.x < 0)

{

scrollView.contentOffset = CGPointMake(WIDTH * 3, scrollView.contentOffset.y);

self.page.currentPage = (scrollView.frame.size.width -WIDTH) / WIDTH;

}

else if (scrollView.contentOffset.x > 3 * WIDTH)

{

scrollView.contentOffset = CGPointMake(0, scrollView.contentOffset.y);

self.page.currentPage = 0;

}

#define HEIGHT  self.view.frame.size.height

#define WIDTH   self.view.frame.size.width

@interface ViewController : UIViewController<UIScrollViewDelegate>

@property (strong,nonatomic) UIScrollView *myScrollV;

@property (strong,nonatomic) UIPageControl *page;

@end

}

时间: 2024-12-26 20:56:06

滚动视图UIScrollView的相关文章

滚动视图 UIScrollView

UIScrollView:提供可以显?示?大于应?用窗??口的内容功能的控件, ?用户可以通过?手势使内容滚动和缩放,从?而查 看全部内容. 初始化一个UIScrollView的对象 1 UIScrollView *_scroll=[[UIScrollView alloc] init]; 首先介绍一下UIScrollView这个类的基本属性 属性:  contentSize     滚动视图的内容大小 //UIScrollView能够滚动的前提是contentsize大于大的本身尺寸.即大于fr

滚动ScrollView---数组存放图片,设置3个滚动视图,用来滑动多张图片

问题描述:循环滑动切换n多张图片,不事先加载完成,现用现取. 解题思路:将要显示的图片存放在数组中,设置3个滚动视图,左边视图,正在显示的视图,右边视图 实现代码如下: //  ViewController.m #import "ViewController.h" #define kWith self.view.frame.size.width #define kHeight self.view.frame.size.height @interface ViewController (

UIScrollView 按页面滚动视图 UIPageControl

1.UIScrollView是可以滚动的view,UIView本?身不能滚动,子类UIScrollview拓展了滚动?方?面的功能. 2.UIScrollView是所有滚动视图的基类.以后的UITableView,UITextView等视图都是继承于该类. 3.UIScrollview主要专?长于两个?方?面: (1).滚动:contentSize?大于frame.size的时候,能够滚动. (2).缩放:?自带缩放,可以指定缩放倍数. UIScrollView滚动的相关属性 1.content

UI开发----UIScrollView和UIPageControl简单模拟滚动视图

//  Created By 郭仔 //================================================== 师傅领进门,修行在个人!自学才是王道! //================================================== UIScrollView: UIScrollView * scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(20, 50, 200, 200)]

UIScrollView(滚动视图)和(UIPageController)页面控制器+ 定时器的使用

////  Teacher_ViewController.m//  友家家教////  Created by 邹贤 on 15/7/28.//  Copyright (c) 2015年 友家科技公司. All rights reserved.// #import "Teacher_ViewController.h" #import "ArtViewController.h" #import "PrimaryViewController.h" #i

Swift - 滚动视图(UIScrollView)的用法

1,当图片尺寸超过屏幕时,使用UIScrollView可以实现滚动条视图,即手指触摸滚动屏幕方便浏览整个页面. 1 2 3 4 5 6 var scrollView=UIScrollView() scrollView.frame=self.view.bounds var imageView=UIImageView(image:UIImage(named:"bigpic")) scrollView.contentSize=imageView.bounds.size; scrollView

UIScrollView 滚动视图的方法总结

UIScrollView的属性总结 属性 作用 CGPoint contentOffSet-------------------------- 监控目前滚动的位置 CGSize contentSize------------------------------ 滚动范围的大小 UIEdgeInsets contentInset--------------------- 视图在scrollView中的位置 id<UIScrollerViewDelegate> delegate------ 设置协

UIScrollVIew 滚动视图内容总结

1 - (void)viewDidLoad 2 3 { 4 5 [super viewDidLoad]; 6 7 // Do any additional setup after loading the view. 8 9 10 11 // 滚动视图 12 13 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 20, 280, 440)]; 14 15 scrollView.backgro

ios &ndash; 滚动视图(UIScrollView)详解

移动的设备的屏幕大小有限,当一个视图要显示的内容大于屏幕尺寸的时候就要用到滚动视图,比如一个网页的内容通常比屏幕尺寸大,那么浏览器就使用了滚动视图.   UIScrollView有一个contentSize属性,声明如下: @property(nonatomic) CGSize contentSize; 这个属性表示滚动视图的内容有多大. 创建滚动视图实例: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup