本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 = CGAff.netransformMakeRotation(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 = CGAff.netransformMakeRotation(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{ }
以上就是本文的全體內容,願望對年夜家的進修有所贊助,也願望年夜家多多支撐本站。
【iOS完成微信同伙圈與搖一搖功效】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!