设为首页 加入收藏

TOP

你真的了解UIScrollView吗?(二)
2017-10-13 09:46:26 】 浏览:7726
Tags:真的 了解 UIScrollView
设置最大缩放倍数,默认值1.0 @property(nonatomic) CGFloat maximumZoomScale; // 当前的缩放倍数 @property(nonatomic) CGFloat zoomScale NS_AVAILABLE_IOS(3_0); // 默认值 1.0 //程序设置缩放大小 - (void)setZoomScale:(CGFloat)scale animated:(BOOL)animated NS_AVAILABLE_IOS(3_0); //将内容视图缩放到指定的Rect中 - (void)zoomToRect:(CGRect)rect animated:(BOOL)animated NS_AVAILABLE_IOS(3_0); //控制缩放的时候是否会反弹 默认值YES @property(nonatomic) BOOL bouncesZoom; // default is YES. if set, user can go past min/max zoom while gesturing and the zoom will animate to the min/max value at gesture end //只读,用户是否正在进行缩放手势 @property(nonatomic,readonly,getter=isZooming) BOOL zooming; //只读,当缩放超过最大或者最小范围的时候,回弹到最大最小范围的过程中,该值返回YES。 @property(nonatomic,readonly,getter=isZoomBouncing) BOOL zoomBouncing; //设置是否可以自动滚动到顶部(点击上面状态栏的时候),默认为true @property(nonatomic) BOOL scrollsToTop; //移动手势 只读 @property(nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer NS_AVAILABLE_IOS(5_0); // 缩放手势 只读 @property(nullable, nonatomic, readonly) UIPinchGestureRecognizer *pinchGestureRecognizer NS_AVAILABLE_IOS(5_0); //当拖动发生时,键盘的消失模式,默认值是不消失UIScrollViewKeyboardDismissModeNone @property(nonatomic) UIScrollViewKeyboardDismissMode keyboardDismissMode NS_AVAILABLE_IOS(7_0); @end

UIScrollView用于显示超出屏幕大小内容,一般需要配合其他控件来使用,如添加一个UIImageView子控件,可以用来显示更大的图片;

UITableView、UICollectionView以及UITextView这些可以滑动显示更多内容的控件,都是UIScrollView的子类;

知识点1关于UIScrollView的各个大小说明

 

知识点2:如果UIScrollView无法滚动,可能是以下原因:

1:没有设置contentSize
2:scrollEnabled = NO
3:没有接收到触摸事件:userInteractionEnabled = NO

 知识点3:iOS7以后,导航控制器会为其中的scrollView的顶部自动添加64的内边距,如果想去掉,可以通过下列属性去掉

self.automaticallyAdjustsScrollViewInsets = NO;

知识点4UIScrollView实现滑动视图实例

//---导入代理
@interface RootViewController ()<UIScrollViewDelegate>

@end

@implementation RootViewController

//viewDidLoad只执行一次
- (void)viewDidLoad {

    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];

    //-创建滚动视图  当我们需要显示的内容超过一屏时,就需要用到滚动视图
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    [scrollView setBackgroundColor:[UIColor orangeColor]];
    [self.view addSubview:scrollView];

    //-Key:设置滚动区域(内容区域的大小)
    scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.view.frame) * 4, CGRectGetHeight(self.view.frame));
    //-为scrollview添加子视图
//    NSArray *colorArr = [NSArray arrayWithObjects:[UIColor cyanColor], [UIColor greenColor],  [UIColor redColor], [UIColor blueColor], nil];
    NSArray *imageArr = [NSArray arrayWithObjects:[UIImage imageNamed: @"woman1.jpg"], [UIImage imageNamed: @"woman2.jpg"], [UIImage imageNamed: @"woman3.jpg"], [UIImage imageNamed:@"woman4.jpg"],  nil];

    for (int i = 0; i < 4; i++) {

        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.frame)*i, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
        label.text = [NSString stringWithFormat:@"这是志南的第%d夫人", i+1];
        label.font = [UIFont systemFontOfSize:30];
        label.textAlignment = NSTextAlignmentCenter;
//        label.backgroundColor = colorArr[i];//

        UIImageView *imageView = [[UIImageView alloc] initWithImage:imageArr[i
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 2/7/7
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇iOS获取app图标和启动图片名字(A.. 下一篇iOS - 数组(NSArray)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目