当前位置: 首页 > news >正文

【iOS】暑期学习总结

暑期学习总结

  • 前言
  • 无限轮播图
  • 换头像
  • 简单的网络请求
  • UISearchController

前言

暑假在学校完成了五个项目,总的来说学习到了很多新的知识,这里对暑假中学习的内容进行一个小的总结,整理一些个人认为比较重点的内容。

无限轮播图

无限轮播图的原理是在轮播的图片两边加上两个假页,通过判断是否到了这两个假页的位置,而后将滚动视图展示位置移动,从而可以实现视觉效果上的无限轮播效果。
在这里插入图片描述
如图所示,当我插入三张图片时,两边的假页分别是第三、一张,这样一来,在展示时当移动到第五张时,函数检测后将滚动视图重置至第二张,就不会有间断效果,前面的移动也是如此。

self.scrollview = [[UIScrollView alloc] init];self.scrollview.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height/2-200, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-320);self.scrollview.pagingEnabled = YES;self.scrollview.scrollEnabled = YES;self.scrollview.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width * 5 , [UIScreen mainScreen].bounds.size.height / 2);for (int i = 0; i <= 5; i++) {NSString *strName = [NSString stringWithFormat:@"%d.JPG", (i % 3) + 1];// 创建图片UIImage *image = [UIImage imageNamed:strName];// 创建视图UIImageView *iView = [[UIImageView alloc] initWithImage:image];if (i == 5) {iView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 300);}else {iView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width * (i + 1), 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 320);}// 将图片添加到滚动视图,不要添加到主视图[self.scrollview addSubview:iView];}[self.view addSubview:self.scrollview];// 设置初始偏移量到第二张图片[self.scrollview setContentOffset:CGPointMake([UIScreen mainScreen].bounds.size.width, 0) animated:NO];// 实现滚动到最后一张视图时,再次滚动能回到第一张视图self.scrollview.delegate = self;- (void)scrollViewDidScroll:(UIScrollView *)scrollView {//当前滚动到的x位置CGFloat X = scrollView.contentOffset.x;//滚动视图展示宽度,即已经滚动过的宽度CGFloat screenWidth = CGRectGetWidth(scrollView.frame);//滚动视图内容的宽度,在我的视图中,就是5个屏幕的宽度CGFloat contentWidth = scrollView.contentSize.width;// 滚动到最后一张视图之后,将滚动位置重置到第二张图片;这样做的话,滚动视图位置被提前,就可以继续对视图进行从左到右的滚动if (X >= contentWidth - screenWidth) {[scrollView setContentOffset:CGPointMake(screenWidth, 0) animated:NO];}// 滚动到第一张视图之前,将滚动位置重置到倒数第二张图片;这样做的话,滚动视图位置被滞后,就可以继续对视图进行从右向左的滚动else if (X < screenWidth - scrollView.frame.size.width) {[scrollView setContentOffset:CGPointMake(contentWidth - 2 * screenWidth, 0) animated:NO];}
}

换头像

这个功能是一个在自己创建的照片墙中选择图片并且传递到上一个页面,在头像框内显示的操作,这里我使用了协议传值的方法,通过将图片传递给上一个界面实现了该功能,这里通过代码展示。

if(self.selectedCount == 0) {self.elertView = [UIAlertController alertControllerWithTitle:@"警告" message:@"请选择一张图片更换" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction* action = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){}];[self.elertView addAction:action];[self presentViewController:self.elertView animated:YES completion:nil];} else if (self.selectedCount == 1) {for(UIView* subview in self.scrollview.subviews) {if([subview isKindOfClass:[UIButton class]]) {UIButton* button = (UIButton*) subview;if(button.selected) {UIImage* image = [button imageForState:UIControlStateNormal];[self.delegate ChangePhoto:image];button.selected = NO;[self.navigationController popViewControllerAnimated:YES];break;}}}} else {self.elertView = [UIAlertController alertControllerWithTitle:@"警告" message:@"禁止一次选用多张图片更换" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction* action = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){}];[self.elertView addAction: action];[self presentViewController:self.elertView animated:YES completion:nil];}

简单的网络请求

简单的网络请求主要有以下几个步骤:

  1. 创建请求地址
  2. 创建请求类
  3. 创建会话
  4. 根据会话创建任务
  5. 启动任务

这里就不详细讲解网络请求的内容了,如果需要了解内容,可以看看本人的这篇博客:【iOS】APP仿写——天气预报
主要需要注意网络请求异步的问题。

UISearchController

UISearchController提供了一个搜索栏和搜索结果视图的管理器,使得在应用中集成搜索功能变得简单。它可以用于在单个视图控制器中添加搜索功能,也可以与其他视图控制器(如UITableViewController)一起使用。 我们要实现UISearchControllerDelegate, UISearchResultsUpdatig两个协议来实现想要显示的效果,下面通过代码展示:

self.search = [[UISearchController alloc] initWithSearchResultsController:nil];self.search.delegate = self;self.search.searchResultsUpdater = self;//设置searchbar的尺寸[self.search.searchBar sizeToFit];//在搜索时将背景模糊化,因为模糊背景的目的是将焦点集中在搜索结果上,而不是与背景内容进行交互。self.search.obscuresBackgroundDuringPresentation = YES;//隐藏导航控制栏self.search.hidesNavigationBarDuringPresentation = YES;//设置未编辑状态的searchbar的位置self.search.searchBar.frame = CGRectMake(0, 150, [UIScreen mainScreen].bounds.size.width, 55);
//    _tableview.tableHeaderView = self.search.searchBar;[self.view addSubview:self.search.searchBar];self.search.searchBar.searchBarStyle = UISearchBarStyleDefault;UISearchBar* searchbar = self.search.searchBar;searchbar.placeholder = @"请输入搜索的城市";

在这里插入图片描述

上面是本人在完成项目中一些觉得比较有代表性的学习的内容,如果你还想了解更多的内容,去看看笔者之前写的博客吧。

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • Windows使用ffmpeg获取麦克风数据
  • 秋招智能体,Offer没难题
  • Netlify 为静态站点部署 Waline 评论系统
  • 智能提醒助理系列-协作工具,一站式软件研发管理平台
  • STM32F103ZETx_FLASH.ld 解析
  • 库(Library)
  • Kafka 常用的传输和序列化数据方式
  • 51单片机——实时时钟
  • 数分基础(06)商业分析四种类型简介
  • 技术Leader在训练团队思考力中的核心职责
  • 环信高质量全球网络——70%丢包环境,消息100%送达,抗弱网能力大幅提升!
  • DAMA数据管理知识体系(第4章 数据架构)
  • B站视频自动驾驶master(2)
  • ARP协议(原理,特点,报文格式,具体过程),ARP缓存(有效时间,为什么),ARP欺骗(定向断网,成为中间人),RARP简单介绍
  • leetcode 2816.翻倍以链表形式表示的数字
  • [译] 怎样写一个基础的编译器
  • Docker 1.12实践:Docker Service、Stack与分布式应用捆绑包
  • Java新版本的开发已正式进入轨道,版本号18.3
  • log4j2输出到kafka
  • scrapy学习之路4(itemloder的使用)
  • Three.js 再探 - 写一个跳一跳极简版游戏
  • 规范化安全开发 KOA 手脚架
  • 聚类分析——Kmeans
  • 少走弯路,给Java 1~5 年程序员的建议
  • 如何在 Intellij IDEA 更高效地将应用部署到容器服务 Kubernetes ...
  • ​3ds Max插件CG MAGIC图形板块为您提升线条效率!
  • ​Distil-Whisper:比Whisper快6倍,体积小50%的语音识别模型
  • ​Redis 实现计数器和限速器的
  • ​软考-高级-系统架构设计师教程(清华第2版)【第20章 系统架构设计师论文写作要点(P717~728)-思维导图】​
  • ​软考-高级-信息系统项目管理师教程 第四版【第19章-配置与变更管理-思维导图】​
  • !!【OpenCV学习】计算两幅图像的重叠区域
  • # centos7下FFmpeg环境部署记录
  • # Panda3d 碰撞检测系统介绍
  • ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTr
  • #pragma预处理命令
  • (2024,RWKV-5/6,RNN,矩阵值注意力状态,数据依赖线性插值,LoRA,多语言分词器)Eagle 和 Finch
  • (a /b)*c的值
  • (多级缓存)多级缓存
  • (二) 初入MySQL 【数据库管理】
  • (二)Eureka服务搭建,服务注册,服务发现
  • (附源码)ssm基于微信小程序的疫苗管理系统 毕业设计 092354
  • (附源码)流浪动物保护平台的设计与实现 毕业设计 161154
  • (十八)三元表达式和列表解析
  • (一)Thymeleaf用法——Thymeleaf简介
  • ./configure,make,make install的作用
  • .NET CORE Aws S3 使用
  • .NET Core使用NPOI导出复杂,美观的Excel详解
  • .Net Core中的内存缓存实现——Redis及MemoryCache(2个可选)方案的实现
  • .Net 执行Linux下多行shell命令方法
  • .Net(C#)常用转换byte转uint32、byte转float等
  • .NET的数据绑定
  • ??Nginx实现会话保持_Nginx会话保持与Redis的结合_Nginx实现四层负载均衡
  • ?php echo $logosrc[0];?,如何在一行中显示logo和标题?
  • [2019.3.20]BZOJ4573 [Zjoi2016]大森林
  • [AIGC] 开源流程引擎哪个好,如何选型?