IOS控件- scrollview

scrollview的delegate与files owner关联

.h文件

#import <UIKit/UIKit.h>

@interface EXSVViewController : UIViewController<UIScrollViewDelegate>

@end


.m文件

//
//  EXSVViewController.m
//  ExerciseScrollView
//
//  Created by hxl on 13-5-21.
//  Copyright (c) 2013年 xiaolei.hu. All rights reserved.
//

#import "EXSVViewController.h"

@interface EXSVViewController ()
@property (nonatomic) IBOutlet UIScrollView *scrollView;//在xib中与scrollview控件关联
@end

@implementation EXSVViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    // Scroll view
    UInt16 h = 6;
    UInt16 w = 6;
    for (UInt16 i = 0; i < h; i++) {
        //CGRectMake(X轴坐标,Y轴坐标,宽,高)
        for (UInt16 j = 0; j < w; j++) {
            //设置图片位置
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(self.scrollView.frame.size.width * i, self.scrollView.frame.size.height * j, self.scrollView.frame.size.width,self.scrollView.frame.size.height)];
            
            // 指定URL生成UIImage
            [button setTitle:@"按钮" forState:UIControlStateNormal]; //设置button的标题
            //[button addTarget:self action:@selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside]; //定义点击时的响应函数
            [button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i+1]] forState:UIControlStateNormal];
            [self.scrollView addSubview:button];

        }
    }
    //NSLog(@"%@",self);
    //等同于在.xlb文件中delegate和File's Owner连接
    //[self.scrollView setDelegate:self];
    [self.scrollView setContentSize:CGSizeMake(self.scrollView.frame.size.width * h, self.scrollView.frame.size.height * w)];
    
    //[self.scrollView setDirectionalLockEnabled:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 typedef enum {
 UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
 UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
 UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
 UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
 } UIInterfaceOrientation;
 */
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    
    return (interfaceOrientation == UIInterfaceOrientationPortrait);//系统默认不支持旋转功能
    //返回YES屏幕所有方向旋转都支持
    //return YES;
}

// 触摸屏幕来滚动画面还是其他的方法使得画面滚动,皆触发该函数
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSLog(@"Scrolling...");
}

// 触摸屏幕并拖拽画面,再松开,最后停止时,触发该函数
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    NSLog(@"scrollViewDidEndDragging  -  End of Scrolling.");
}

// 滚动停止时,触发该函数
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSLog(@"scrollViewDidEndDecelerating  -   End of Scrolling.");
}

// 调用以下函数,来自动滚动到想要的位置,此过程中设置有动画效果,停止时,触发该函数
// UIScrollView的setContentOffset:animated:
// UIScrollView的scrollRectToVisible:animated:
// UITableView的scrollToRowAtIndexPath:atScrollPosition:animated:
// UITableView的selectRowAtIndexPath:animated:scrollPosition:
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
    NSLog(@"scrollViewDidEndScrollingAnimation  -   End of Scrolling.");
}

@end


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值