国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS實現(xiàn)微信朋友圈與搖一搖功能

2019-10-21 18:53:17
字體:
供稿:網(wǎng)友

本Demo為練手小項目,主要是熟悉目前主流APP的架構(gòu)模式.此項目中采用MVC設(shè)計模式,純代碼和少許XIB方式實現(xiàn).主要實現(xiàn)了朋友圈功能和搖一搖功能.

預(yù)覽效果:

iOS微信朋友圈,iOS微信搖一搖,iOS朋友圈,iOS搖一搖

主要重點

1.整體架構(gòu)

利用UITabBarController和UINavigationController配合實現(xiàn).其中要注意定義基類,方便整體上的管理,例如對UINavigationController頭部的顏色,字體和渲染顏色等設(shè)置.以及對UITabBarController的底部的渲染等.

[self.navigationBarsetBackgroundImage:[UIImageimageNamed:@"Dimensional-_Code_Bg"]forBarMetrics:UIBarMetricsDefault];    [self.navigationBarsetTitleTextAttributes:@{                       NSForegroundColorAttributeName:[UIColor whiteColor]                      }]; [self.navigationBarsetTintColor:[UIColor whiteColor]];

2.發(fā)現(xiàn)界面和我的界面

利用UITableViewController和Plist文件實現(xiàn)界面的展示.實現(xiàn)過程中有采用數(shù)據(jù)模型或直接利用字典等方式.這里的實現(xiàn)比較簡單,就不多說啦.

- (instancetype)initWithDict:(NSDictionary *)dict{ if (self = [super init]) {  [selfsetValuesForKeysWithDictionary:dict];}return self;} + (instancetype)pictureWithDict:(NSDictionary *)dict{ return [[self alloc]initWithDict:dict];}

3.朋友圈功能的實現(xiàn)

這里面主要的難點在于朋友圈首頁的下拉刷新效果的實現(xiàn),和選擇照片頁的狀態(tài)重用問題,以及照片的傳遞和代理的實現(xiàn)等.

朋友圈首頁的下拉刷新效果:主要利用transform屬性和scrollview的多種滾動狀態(tài).

- (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來實現(xiàn)的.沒有直接調(diào)用系統(tǒng)的相冊,因此加大了難度.自定義了cell,并采用了代理方式來實現(xiàn)類與類之間的通信.

@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.搖一搖功能的實現(xiàn)

搖一搖功能的本身實現(xiàn)十分簡單,就是調(diào)用系統(tǒng)的兩個方法即可.難點在于動畫效果.其實這里的動畫效果也不是很難.主要是計算有點復(fù)雜.可能是我在網(wǎng)上搜索到的素材有點不合適.導(dǎo)致要考慮各個控件的frame問題…

 

//實現(xiàn)搖一搖功能- (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];  }]; }];}//搖一搖結(jié)束后- (void)motionEnded:(UIEventSubtype)motionwithEvent:(UIEvent *)event{ }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到IOS開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 浏阳市| 确山县| 宜州市| 碌曲县| 舟曲县| 屏山县| 田阳县| 稻城县| 商丘市| 武乡县| 潼南县| 永修县| 泸水县| 林口县| 二手房| 包头市| 汨罗市| 黑水县| 惠水县| 滦南县| 景谷| 班玛县| 黎城县| 永胜县| 高碑店市| 法库县| 织金县| 右玉县| 始兴县| 额济纳旗| 武陟县| 大邑县| 凉山| 德安县| 汝州市| 奎屯市| 清水县| 平南县| 平湖市| 桑日县| 澜沧|