UIScrollView-滚动控件

UIScrollView相关代理方法:
https://www.cnblogs.com/liuting-1204/p/5960815.html

iOS开发-图片查看(ScrollView+UIPageControl)
https://www.cnblogs.com/xiaofeixiang/p/4242919.html

ios开发scrollView中contentSize、contentInset和contentOffset区别
https://www.jianshu.com/p/e766f09f043b

//
//  ViewController.m
//  UIScrollView-滚动视图
//
//  Created by Liu,Wenbo(TBRD) on 2020/5/29.
//  Copyright © 2020 Liu,Wenbo(TBRD). All rights reserved.
//

#import "ViewController.h"

@interface ViewController () <UIScrollViewDelegate> //设置代理
{
    UIScrollView *scrollview;
    UILabel *lable;
    UIImageView *imageView;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    scrollview = [[UIScrollView alloc] initWithFrame:self.view.frame];
    scrollview.backgroundColor = [UIColor grayColor];
    
    UIImage *image = [UIImage imageNamed:@"test1.png"];
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];
    imageView.image = image;
    
    [scrollview addSubview:imageView];
    
    lable = [[UILabel alloc] initWithFrame:CGRectMake(150, 150, 100, 100)];
    lable.backgroundColor = [UIColor whiteColor];
    
    //设置滚动视图的内容区域
    scrollview.contentSize = CGSizeMake(self.view.frame.size.width * 2, self.view.frame.size.height * 2);
    
    //设置内容区域位置的偏移量 这里设置到了最右边
    scrollview.contentOffset = CGPointMake(self.view.frame.size.width, 0);
    
    //设置内容区域大小的偏移量  这里相当于多加一个屏幕的大小
    scrollview.contentInset = UIEdgeInsetsMake(0, self.view.frame.size.width, 0, 0);
    
    //设置代理
    scrollview.delegate = self;
    
    //方向锁定 先水平滑动则限定水平滑动(既不能垂直滑动);先垂直滑动的话就限定垂直滑动;但是对角线上没有限定
    scrollview.directionalLockEnabled = YES;
    
    //设置是否允许回弹
    scrollview.bounces = NO;
    
    //设置滑动提示线是否显示
    //scrollview.showsVerticalScrollIndicator = YES;
    
    //设置提示线的风格
    scrollview.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    
    //设置scrollview的加速度
    //scrollview.decelerationRate = 0.5;
    
    //设置scrollview的缩放比
    scrollview.minimumZoomScale = 0.5; // 最小缩0.5
    scrollview.maximumZoomScale = 2; //最大扩大2
   
    
    [scrollview addSubview:lable];
    [self.view addSubview: scrollview];
}

//想缩放哪个控件就返回哪个控件
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return imageView;
}
@end

手势扩大或缩小按住option键即可操作

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值