[IOS笔记]UIScrollView属性
来源:互联网 发布:数据库设计原则,范式 编辑:程序博客网 时间:2024/06/06 18:42
//// ViewController.m// UIScrollView展示大图片//// Created by cdj on 17/9/10.// Copyright © 2017年 ue. All rights reserved.//#import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad];/* UIImage *image = [UIImage imageNamed:@"minion"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; [self.scrollView addSubview:imageView]; // 设置contentSize// self.scrollView.contentSize = CGSizeMake(510, 510);// self.scrollView.contentSize = imageView.frame.size; self.scrollView.contentSize = image.size; // 去掉弹簧效果// self.scrollView.bounces = NO;// self.scrollView.alwaysBounceHorizontal = NO;// self.scrollView.alwaysBounceVertical = NO; // 默认显示滚动条 self.scrollView.showsHorizontalScrollIndicator = NO; self.scrollView.showsVerticalScrollIndicator = YES; NSLog(@"%@", self.scrollView.subviews); // 注意:不要通过索引去subviews数组访问scrollView子控件// [self.scrollView.subviews.firstObject removeFromSuperview]; */ /*// 下拉刷新的菊花 UIActivityIndicatorView *indicatorView =[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; indicatorView.center = CGPointMake(100, -40); [indicatorView startAnimating]; [self.scrollView addSubview:indicatorView]; self.scrollView.alwaysBounceHorizontal = YES; self.scrollView.alwaysBounceVertical = YES; */ UIImage *image = [UIImage imageNamed:@"minion"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; [self.scrollView addSubview:imageView]; self.scrollView.contentSize = image.size; // 内容的偏移量,作用:控制内容滚动的位置;得知内容滚动的位置 self.scrollView.contentOffset = CGPointMake(100, 100); // 设置剩余的内边距:作用 self.scrollView.contentInset = UIEdgeInsetsMake(10, 20, 30, 40); }/** * Description点击控制器的view会自动调用这个方法 * * @param touches <#touches description#> * @param event <#event description#> */-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ NSLog(@"touchesBegan"); self.scrollView.contentOffset = CGPointMake(-100, -100);}- (IBAction)top { /*// 方式一 CGPoint offset = self.scrollView.contentOffset; offset.y = 0; self.scrollView.contentOffset = offset; */ // 方式二// self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, 0); // 方式三:有动画,但是无法设定时间// [self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, 0) animated:YES]; // 方式四 [UIView animateWithDuration:2.0 animations:^{ self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, 0); }];}- (IBAction)bottom { CGFloat offsetX = self.scrollView.contentOffset.x; CGFloat offsetY = self.scrollView.contentSize.height - self.scrollView.frame.size.height; CGPoint offset = CGPointMake(offsetX, offsetY); [self.scrollView setContentOffset:offset animated:YES];}- (IBAction)left { [self.scrollView setContentOffset:CGPointMake(0, self.scrollView.contentOffset.y) animated:YES];}- (IBAction)right { CGFloat offsetX = self.scrollView.contentSize.width - self.scrollView.frame.size.width; CGFloat offsetY = self.scrollView.contentOffset.y; CGPoint offset = CGPointMake(offsetX, offsetY); [self.scrollView setContentOffset:offset animated:YES]; }- (IBAction)rightTop { CGFloat offsetX = self.scrollView.contentSize.width - self.scrollView.frame.size.width; CGFloat offsetY = 0; CGPoint offset = CGPointMake(offsetX, offsetY); [self.scrollView setContentOffset:offset animated:YES];}- (IBAction)leftBottom { CGFloat offsetX = 0; CGFloat offsetY = self.scrollView.contentSize.height - self.scrollView.frame.size.height; CGPoint offset = CGPointMake(offsetX, offsetY); [self.scrollView setContentOffset:offset animated:YES];}@end
阅读全文
0 0
- [IOS笔记]UIScrollView属性
- IOS笔记——UIScrollView属性介绍
- iOS中UIScrollView属性
- ios UIScrollView 一些属性
- iOS UIScrollView属性介绍
- iOS UIScrollView的属性
- ios UIScrollView属性介绍
- iOS学习笔记-019.UIScrollView的基本属性和用法
- iOS 学习笔记 uiscrollview
- iOS: UIScrollView的属性alwaysBounceHorizontal
- iOS: UIScrollView的属性alwaysBounceVertical
- iOS: UIScrollView的属性bounces
- iOS: UIScrollView的属性bouncesZoom
- iOS: UIScrollView的属性canCancelContentTouches
- iOS: UIScrollView的属性contentInset
- iOS: UIScrollView的属性contentOffset
- iOS: UIScrollView的属性decelerating
- iOS: UIScrollView的属性decelerationRate
- HDU 5772 String problem(一个诡异的建图)
- java常用的输入输出调试技巧
- 正则表达式 反义
- MyEclipse 2017 CI 7安装与激活
- [LeetCode] 258. Add Digits
- [IOS笔记]UIScrollView属性
- ES6之数组(array)
- 【Python】简单学习(一)
- IntelliJ IDEA使用之一—打开Settings
- 美国全力封杀卡巴斯基
- POP3遇到的编码问题
- [Project] Simulate HTTP Post Request to obtain data from Web Page by using Python Scrapy Framework
- 微软2017年预科生计划在线编程笔试第二场-#1497 : Queen Attack
- 正则表达式 分支条件