#import "ViewController.h"
@interface ViewController ()<UIScrollViewDelegate>
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// 设置内容尺寸
self.scrollView.contentSize = self.imageView.frame.size;
// 设置
self.scrollView.delegate = self;
// 设置最大和最小的缩放比例
self.scrollView.maximumZoomScale = 2.0;
self.scrollView.minimumZoomScale = 0.2;
// 设置边距
self.scrollView.contentInset = UIEdgeInsetsMake(20, 20, 20, 20);
// 不显示水平滚动标示
self.scrollView.showsHorizontalScrollIndicator = NO;
// 不显示垂直滚动标示
self.scrollView.showsVerticalScrollIndicator = NO;
// 偏移位置
self.scrollView.contentOffset = CGPointMake(0, -100);
// 取消弹簧效果
self.scrollView.bounces = NO;
//设置按钮
UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
btn.center = self.view.center;
[self.view addSubview:btn];
//设置按钮的监听方法
[btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
}
// 移动大图的偏移位置
- (void)click
{
//取出offset
CGPoint offset = self.scrollView.contentOffset;
offset.x += 20;
offset.y += 20;
// 更新contentOffset
self.scrollView.contentOffset = offset;
}
#pragma mark - UIScrollView的代理方法
// 1> scrollView要知道缩放谁
/**
* 当用户开始拖拽scrollView时就会调用
*/
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
NSLog(@"开始拖拽");
}
/**
* 只要scrollView正在滚动,就会调用
*/
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"正在滚动%@", NSStringFromCGPoint(scrollView.contentOffset));
}
/**
* 当用户使用捏合手势的时候会调用
*
* @return 返回的控件就是需要进行缩放的控件
*/
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
NSLog(@"开始缩放");
return self.imageView;
}
/**
* 正在缩放的时候会调用
*/
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
NSLog(@"正在缩放");
}
@end
self.scrollView.contentInset = UIEdgeInsetsMake(20, 20, 20, 20);
UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
- (void)click
{
CGPoint offset = self.scrollView.contentOffset;
offset.x += 20;
offset.y += 20;
self.scrollView.contentOffset = offset;
}
@property(nonatomic) UIEdgeInsets contentInset; 这个属性能够在UIScrollView的4周增加额外的滚动区域 @property(nonatomic) CGPoint contentOffset; 这个属性用来表示UIScrollView滚动的位置 @property(nonatomic) CGSize contentSize; 这个属性用来表示UIScrollView内容的尺寸,滚动范围(能滚多远) @property(nonatomic) BOOL bounces; 设置UIScrollView是否需要弹簧效果 @property(nonatomic,getter=isScrollEnabled) BOOL scrollEnabled; 设置UIScrollView是否能滚动 @property(nonatomic) BOOL showsHorizontalScrollIndicator; 是否显示水平滚动条 @property(nonatomic) BOOL showsVerticalScrollIndicator; 是否显示垂直滚动条
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有