iOS实现微信朋友圈与摇一摇功能
作者:lijiao 发布时间:2023-06-16 13:59:48
标签:iOS,微信,朋友圈,摇一摇
本Demo为练手小项目,主要是熟悉目前主流APP的架构模式.此项目中采用MVC设计模式,纯代码和少许XIB方式实现.主要实现了朋友圈功能和摇一摇功能.
预览效果:
主要重点
1.整体架构
利用UITabBarController和UINavigationController配合实现.其中要注意定义基类,方便整体上的管理,例如对UINavigationController头部的颜色,字体和渲染颜色等设置.以及对UITabBarController的底部的渲染等.
[self.navigationBarsetBackgroundImage:[UIImageimageNamed:@"Dimensional-_Code_Bg"]forBarMetrics:UIBarMetricsDefault];
[self.navigationBarsetTitleTextAttributes:@{
NSForegroundColorAttributeName:[UIColor whiteColor]
}];
[self.navigationBarsetTintColor:[UIColor whiteColor]];
2.发现界面和我的界面
利用UITableViewController和Plist文件实现界面的展示.实现过程中有采用数据模型或直接利用字典等方式.这里的实现比较简单,就不多说啦.
- (instancetype)initWithDict:(NSDictionary *)dict{
if (self = [super init]) {
[selfsetValuesForKeysWithDictionary:dict];
}
return self;
}
+ (instancetype)pictureWithDict:(NSDictionary *)dict{
return [[self alloc]initWithDict:dict];
}
3.朋友圈功能的实现
这里面主要的难点在于朋友圈首页的下拉刷新效果的实现,和选择照片页的状态重用问题,以及照片的传递和代理的实现等.
朋友圈首页的下拉刷新效果:主要利用transform属性和scrollview的多种滚动状态.
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
self.dragging = YES;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (self.num == 0) {
self.num ++;
return;
}
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat angle = -offsetY* M_PI / 30;
if (self.dragging == YES) {
if (offsetY <= 110) {
self.containerView.y = 10 + offsetY;
}
}else {
if (self.currentY < 120) {
self.containerView.y = 10 + offsetY;
}
}
self.activityView.transform = CGAffineTransformMakeRotation(angle);
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollViewwillDecelerate:(BOOL)decelerate{
self.dragging = NO;
CGFloat currentY = self.containerView.y;
self.currentY = currentY;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
[UIViewanimateWithDuration:0.25animations:^{
self.containerView.frame = CGRectMake(15, 120, 30, 30);
self.activityView.transform = CGAffineTransformMakeRotation(2 * M_PI);
}];
}
其中照片的展示是采用UICollectionViewController来实现的.没有直接调用系统的相册,因此加大了难度.自定义了cell,并采用了代理方式来实现类与类之间的通信.
@protocol YYPictureCellDelegate
@optional
- (void)pictureCell:(YYPictureCell *)cellwithDidClickBtn:(UIButton *)btn;
@end
- (IBAction)clickSureBtn:(UIButton *)sender {
if ([self.delegaterespondsToSelector:@selector(pictureCell:withDidClickBtn:)]) {
[self.delegatepictureCell:selfwithDidClickBtn:sender];
}
}
- (void)pictureCell:(YYPictureCell *)cellwithDidClickBtn:(UIButton *)btn{
if ((self.selectedBtn.count == 9) && (!btn.isSelected)) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nilmessage:@"最多选取9张照片哦,亲!"delegate:nilcancelButtonTitle:@"确定"otherButtonTitles: nil];
[alertshow];
return;
}
btn.selected = !btn.isSelected;
NSIndexPath *indexPath = [self.collectionViewindexPathForCell:cell];
YYPictureModel *model = self.dataArray[indexPath.row];
if (btn.isSelected) {
model.clickedBtn = YES;
[self.selectedBtnaddObject:btn];
[self.selImageArrayaddObject:model];
} else{
model.clickedBtn = NO;
[self.selectedBtnremoveObject:btn];
[self.selImageArrayremoveObject:model];
}
if (self.selectedBtn.count > 0) {
self.doneBtn.enabled = YES;
self.doneBtn.selected = YES;
self.previewBtn.enabled = YES;
self.previewBtn.selected = YES;
}else {
self.doneBtn.enabled = NO;
self.doneBtn.selected = NO;
self.previewBtn.enabled = NO;
self.previewBtn.selected = NO;
}
}
4.摇一摇功能的实现
摇一摇功能的本身实现十分简单,就是调用系统的两个方法即可.难点在于动画效果.其实这里的动画效果也不是很难.主要是计算有点复杂.可能是我在网上搜索到的素材有点不合适.导致要考虑各个控件的frame问题…
//实现摇一摇功能
- (void)motionBegan:(UIEventSubtype)motionwithEvent:(UIEvent *)event{
self.upLine.hidden = NO;
self.downLine.hidden = NO;
[UIViewanimateWithDuration:0.6animations:^{
self.upImageView.y -= 60;
self.upLine.y -= 60;
self.downImageView.y += 60;
self.downLine.y += 60;
}completion:^(BOOL finished) {
[UIViewanimateWithDuration:0.6animations:^{
self.upImageView.y += 60;
self.upLine.y += 60;
self.downImageView.y -= 60;
self.downLine.y -= 60;
}completion:^(BOOL finished) {
self.upLine.hidden = YES;
self.downLine.hidden = YES;
//弹出搜索框
[self showSearchView];
[self.searchViewperformSelector:@selector(removeFromSuperview)withObject:nilafterDelay:2.4];
}];
}];
}
//摇一摇结束后
- (void)motionEnded:(UIEventSubtype)motionwithEvent:(UIEvent *)event{
}


猜你喜欢
- 简单介绍下功能1.每隔一段时间(比如1分钟)在京东手机每日一秒杀页面提取产品(手机)链接。 http://sale.360buy.com/a
- 本文实例讲述了Java基于Runtime调用外部程序出现阻塞的解决方法, 是一个很实用的技巧。分享给大家供大家参考。具体分析如下:有时候在j
- Android实现分享长图并且添加全图水印前言:长图一般是ScrollView和ListView。 我们需要取得这两个控件的完整显示的图片。
- 本文实例讲述了C#获取指定PDF文件页数的方法。分享给大家供大家参考。具体如下:using System;using System.IO;u
- 本文实例为大家分享了Android SeekBar实现平滑滚动的具体代码,供大家参考,具体内容如下由于项目需要,SeekBar只需要三个档,
- 实践过程效果代码public partial class Form1 : Form{ public Form1()
- 前言Condition是在Spring4.0增加的条件判断功能,通过这个功能可以实现选择性的创建Bean对象。引入一个例子SpringBoo
- 引言垃圾收集技术并不是Java语言首创的,1960年诞生于MIT的Lisp是第一门真正使用内存动态分配和垃圾收集技术的语言。垃圾收集技术需要
- 在前面的博客中,https://www.jb51.net/article/134866.htm 我们使用了spring boot的异步操作,
- 一、关系型数据库SQLIte 每个应用程序都要使用数据,
- 1、启动新Activty1.1、功能分析App功能在第一个Activity输入消息点击第一个Activity的发送按钮发送消息到第二个Act
- 相对于Swing来说,JavaFX在UI上改善了很多,不仅可以通过FXML来排版布局界面,同时也可以通过CSS样式表来美化UI。其实在开发J
- 本文实例讲述了Android自动朗读TTS用法。分享给大家供大家参考,具体如下:TextToSpeech简称 TTS,是自Android 1
- 初学线程时,总是将 run 方法和 start 方法搞混,虽然二者是完全不同的两个方法,但刚开始使用时很难分清,原因就是因为初次使用时效果貌
- 本节讲运行在后台服务里的工作请求,如何向发送请求者报告状态。推荐用LocalBroadcastManager发送和接收状态,它限制了只有本a
- tcp客户端示例#include <errno.h> #include <sys/socket.h> #includ
- 1 编程语言简介编程语言(programming language)可以简单的理解为一种计算机和人都能识别的语言。一种计算机语言让程序员能够
- 一般在web应用中,对客户端提交上来的图片肯定需要进行压缩的。尤其是比较大的图片,如果不经过压缩会导致页面变的很大,打开速度比较慢,当然了如
- 刚开始学习Service的时候以为它是一个线程的封装,也可以执行耗时操作。其实不然,Service是运行在主线程的。直接执行耗时操作是会阻塞
- 背景分析在项目的开发中,不管是对底层的数据逻辑操作过程,还是业务逻辑的处理过程,还是控制逻辑的处理过程,都不可避免会遇到各种可预知的、不可预