iOS DeveloperiOS学习专题

iOS 龙的天空 (Obj-c)

2016-08-23  本文已影响753人  myusername

联系方式


Head


About


先来几张效果图吧


1.首页 首页.png

- (void)setFrame:(CGRect)frame{ 
static CGFloat margin = 10;  
frame.origin.x = margin;    
frame.size.width -= 2 * frame.origin.x;  
frame.origin.y += margin;  
frame.size.height -= margin;   
[super setFrame:frame];}

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(10, 0, self.frame.size.width-20, self.frame.size.height)];
view.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.00];
view.layer.cornerRadius = 15;
view.layer.masksToBounds = YES;
self.selectedBackgroundView = view;

2.几种cell的自定义

A.png B.png

string = [NSString stringWithFormat:@"<head><style>img{max-width:14;max-height:14}</style></head>%@",string];
NSMutableAttributedString * messageAttrStr = [[NSMutableAttributedString alloc] initWithData:[string dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil]; ```


Time.png
-(void)setTimeText:(NSInteger)dataLine{   
 NSString * timeString;  
  NSDate * todayDate = [NSDate date];//当前时间    
NSDate * pastDate = [NSDate dateWithTimeIntervalSince1970:dataLine];//发帖时间
    NSDateFormatter * format = [[NSDateFormatter alloc] init];  
  NSCalendar * calendar = [NSCalendar currentCalendar]; 
   NSInteger unit =  NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond; 
   NSDateComponents * comDate =  [calendar components:unit fromDate:pastDate toDate:todayDate options:NSCalendarWrapComponents];//时间差值的组件
  if (comDate.year < 1) {//判断是否今年   
        if ([calendar isDateInToday:pastDate]) {//判断是否今天   
           if (comDate.hour >= 1) {//判断是否大于1小时 
               format.dateFormat = @"今天HH:mm";             
               timeString = [format stringFromDate:pastDate];      
            }else if(comDate.hour < 1 && comDate.minute >= 1){            //判断是否小于1小时     
               timeString = [NSString stringWithFormat:@"%2ld分钟前",(long)comDate.minute];      
            }else if(comDate.hour < 1 && comDate.minute < 1 && comDate.second >= 0){//判断是否在一分钟内
                timeString =@"刚刚";         
             }     
        }else if ([calendar isDateInYesterday:pastDate]){  //判断是否昨天      
          format.dateFormat = @"昨天HH:mm";       
           timeString = [format stringFromDate:pastDate];     
        }else{ // 前天之前       
          format.dateFormat = @"MM-dd HH:mm";       
          timeString = [format stringFromDate:pastDate];     
         }  
  }else{ 
       format.dateFormat = @"yyyy-MM-dd HH:mm";
       timeString = [format stringFromDate:pastDate];  
  }  
  _time.text = timeString;
}

3.消息界面的搭建

消息.png

4.板块的业务逻辑实现

板块.png

5.搜索界面

搜索.png

5.1搜索帖子列表

Paste_Image.png

6.发帖回帖

  1. 发帖


    发帖.png
  2. 回帖


    回帖.png
 #pragma mark - 当键盘出现或改变时调用
- (void)keyboardDidShow:(NSNotification *)aNotification{ 
   _keyHidden=NO;  
  NSDictionary *userInfo = [aNotification userInfo]; 
  NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; 
  CGRect keyboardRect = [aValue CGRectValue];  
  CGFloat height = keyboardRect.size.height;  
  CGFloat y  = keyboardRect.origin.y;  
  _keyHeight = height; 
  _keyY = y;  
  if (self.post==nil) {    
    return; 
  } 
  if (self.post.message.isFirstResponder==YES||self.post.title.isFirstResponder==YES) {    
    if (self.post.frame.origin.y==0) {    
        [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionLayoutSubviews animations:^{  
              self.post.frame=CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-self.keyHeight-topHeight);   
         } completion:nil];        
     }else{       
         CGFloat maxY =  self.post.frame.size.height+topHeight+self.post.frame.origin.y;  
          if (maxY>_keyY) {        
        [UIView animateWithDuration:0.1 animations:^{   
               CGRect ract = self.post.frame;    
               ract.origin.y=[UIScreen mainScreen].bounds.size.height-topHeight-(self.post.frame.size.height+_keyHeight); 
               self.postY = ract.origin.y;       
               self.post.frame = ract;        
        }];         
         }else{         
              self.postY = self.post.frame.origin.y;     
         }       
     } 
   }
}

NSString * nullString = @" ";
urlText = [nullString stringByAppendingString:urlText];
urlText = [urlText stringByAppendingString:@" "];
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:urlText];
UITextPosition * beginning = weakSelf.post.message.beginningOfDocument;
UITextRange* selectedRange = weakSelf.post.message.selectedTextRange;
UITextPosition* selectionStart = selectedRange.start;
UITextPosition* selectionEnd = selectedRange.end;
NSInteger location = [weakSelf.post.message offsetFromPosition:beginning toPosition:selectionStart];
NSInteger length = [weakSelf.post.message offsetFromPosition:selectionStart toPosition:selectionEnd];
NSRange range = NSMakeRange(location, length);[weakSelf.post.message.textStorage insertAttributedString:attributeString atIndex:range.location];
[weakSelf.post.message.textStorage addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:1.00 green:0.42 blue:0.42 alpha:1.00], NSLinkAttributeName:[NSURL URLWithString:URL],NSFontAttributeName:[UIFont systemFontOfSize:14]} range:NSMakeRange(range.location+1, urlText.length-2)];
[weakSelf.post.message.textStorage addAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:14]} range:NSMakeRange(range.location+urlText.length-1, 1)];
[weakSelf.post.message.textStorage addAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:14]} range:NSMakeRange(range.location, 1)];weakSelf.post.message.selectedRange=NSMakeRange(weakSelf.post.message.text.length,0);

7.用户界面 用户界面.png


8.设置界面 Paste_Image.png

NSString  *Path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
- (NSInteger)getSizeOfPath:(NSString *)Path {
    NSFileManager *mgr = [NSFileManager defaultManager];
    NSArray *subpaths = [mgr subpathsAtPath:Path];
    NSInteger totalSize = 0;
    for (NSString *subPath in subpaths) {  
      NSString *filePath = [directoryPath stringByAppendingPathComponent:subPath];
        NSInteger fileSize = (long)[[mgr attributesOfItemAtPath:filePath error:nil] fileSize];  
      totalSize += fileSize;  
  }  
  return totalSize;
}
NSString  *Path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
- (void)removePath:(NSString *)Path { 
   NSFileManager *mgr = [NSFileManager defaultManager]; 
   NSArray *subPaths = [mgr contentsOfDirectoryAtPath:Path error:nil]; 
   for (NSString *subPath in subPaths) {   
     NSString *filePath = [directoryPath stringByAppendingPathComponent:subPath];   
     [mgr removeItemAtPath:filePath error:nil];  
  }
}

9.具体帖子内容界面 Paste_Image.png

9.1控件布局

9.2内容布局 Paste_Image.png

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler ;

里的url链接来进行判断处理。

VIPhotoViewDemo


10.其他

1.点击Tabbar按钮实现滑动到顶部或刷新

Paste_Image.png 首先是在自定义的UITabBarController里的UITabBarControllerDelegate的方法
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;```
里面来判断当前点击的是哪个按钮对应的控制器,然后根据控制器的`view`的`contentOffset`来判断是否已经在顶部,不在则滑动到顶部,在则执行刷新操作。

---
3.框架使用
- 网络请求  [AFNetworking](https://github.com/AFNetworking/AFNetworking)
- 图片下载  [SDWebImage](https://github.com/rs/SDWebImage)
- 数据解析  [MJExtension](https://github.com/CoderMJLee/MJExtension)
- HUD显示 [SVProgressHUD](https://github.com/SVProgressHUD/SVProgressHUD)
- 刷      新   [MJRefresh](https://github.com/CoderMJLee/MJRefresh)
- 崩溃日志  [Bugly](https://github.com/BuglyDevTeam/Bugly-iOS)
- 然后框架导入使用的CocoaPods,不过最近Carthage比较流行,最近也在学习Carthage。
---
4.这是我的第一个正式且上架的APP,所以也一直在更新中,主要是在iPhone手机上使用,所以在iPad上显示时会出现有些布局样式不一样,因为没有进行iPad专门的适配,都是交给系统来做的。然后因为第一个嘛,所以怕不熟练,用的是最熟的OC写的,不过接下来的几个APP已经转swift了,swift写起来还是很舒服的。

---
## 11.最后因为我当初代码是直接提交到国内的Coding上去的,还是私有库,同时因为懒癌,所以就没有再上传到github上,所以大家是看不到代码了(话说代码我写的有些乱,也没多少注释。)
上一篇 下一篇

猜你喜欢

热点阅读