项目-旅拍

来源:互联网 发布:cp什么意思网络用语 编辑:程序博客网 时间:2024/04/29 20:19

//

//  ViewController.m

//  我的旅拍1.0

//

//  Created by  on 15/7/6.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "ViewController.h"

#import "UIUtils.h"

#import "SetViewController.h"

#import "MylistViewController.h"

#import "LocalDraftViewController.h"

#import "MainView.h"

#import "EditView.h"

#import "ImageInfo.h"

#import "Header.h"

#import "AFNetworking.h"

#import "WebInfo.h"

#import "WebViewController.h"

#import "PostProgressView.h"

#import "FMDB.h"

#import "FMDBTool.h"


#define Table_Name @"draft_table"


@interface ViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,MainViewDelegate,EditViewDelegate,UIAlertViewDelegate>

{

   MainView *_mainView;//主视图

   EditView *_editView;//编辑视图

   NSMutableArray *_imageInfoArray;//图片信息对象数组

   int _editIndex;//被编辑的索引

   UpdateType _updateType;//更新类型

   PostProgressView *_postProgressView;//上传进度

    

   FMDatabase *_db;//数据库

}

@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    self.view.backgroundColor=[UIColorlightGrayColor];

    _imageInfoArray=[[NSMutableArrayalloc]init];

    

    //设置状态栏为白色

    [selfsetStatusBarColor];

    //添加主视图

    [selfaddMainView];

    //添加编辑视图

    [selfaddEditView];

}


-(void)viewWillAppear:(BOOL)animated

{

    [superviewWillAppear:animated];

    //向前放大动画效果

    [selfscaleAnimationForward];

}


//更新

-(void)updateImageInfo:(ImageInfo *)imageInfo updateType:(UpdateType)updateType index:(int)index

{

    if (updateType ==UPDATETYPE_FOR_ADD_ONE_OBJECT) {

        [_imageInfoArrayaddObject:imageInfo];

    }elseif (updateType ==UPDATETYPE_FOR_EDIT_ONE_OBJECT){

        [_imageInfoArrayreplaceObjectAtIndex:indexwithObject:imageInfo];

    }elseif (updateType ==UPDATETYPE_FOR_DELETE_ONE_OBJECT){

         [_imageInfoArrayremoveObjectAtIndex:index];

    }elseif (updateType ==UPDATETYPE_FOR_DELETE_ALL_OBJECTS){

        [_imageInfoArrayremoveAllObjects];

    }

    

    //如果_imageInfoArray的内容为空则显示MainView否则显示EditView

    if (_imageInfoArray.count ==0) {

        _editView.titleView.text =@"";

        [selfshowMainViewAnimation];

    }else{

        [selfshowEditViewAnimation];

    }

   

    //刷新_editViewtableView中显示的内容

    [_editViewreloadEditViewWithArray:_imageInfoArrayandUpdateType:updateType];

}


//上传多张图片

-(void)uploadImages

{

    if ([UIUtilsisBlankString:_editView.titleView.text]) {

        [_editViewtapTitleView];

    }else{

        

        [selfshowPostProgressView];

        

        //AFNetworking发送图片到服务器

       NSString *urlString = [NSStringstringWithFormat:@"%@%@",LocalWebSite,Request_Upload];

        

       //参数字典

       NSString *uploadTimeString = [selfgetCurrentDateString];

       NSString *pageCountString = [NSStringstringWithFormat:@"%d",(int)_imageInfoArray.count];

       NSString *userIDString = [USER_DEFAULTobjectForKey:@"UserId"];

       NSString *titleString =_editView.titleView.text;

       NSDictionary *parameters = [NSDictionarydictionaryWithObjectsAndKeys:@"ios",@"platform",uploadTimeString,@"uploadTime",pageCountString,@"pageCount",userIDString,@"userId",titleString,@"title",nil];

        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];

        //设置请求可以接受的内容的样式

        manager.responseSerializer.acceptableContentTypes = [NSSetsetWithObject:@"text/html"];

       AFHTTPRequestOperation *uploadOperation = [managerPOST:urlStringparameters: parametersconstructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

            

           for (int i=0; i<_imageInfoArray.count; i++) {

               ImageInfo *imageInfo =_imageInfoArray[i];

               UIImage *image = imageInfo.image;

               NSData *imageData =UIImageJPEGRepresentation(image, 1.0);

               //添加图片

                [formDataappendPartWithFileData:imageDataname:[NSStringstringWithFormat:@"image%d",i+1]fileName:@"image"mimeType:@"image/jpg"];

               if (![UIUtilsisBlankString:imageInfo.text]) {

                   //添加文字

                    [formDataappendPartWithFormData:[imageInfo.textdataUsingEncoding:NSUTF8StringEncoding]name:[NSStringstringWithFormat:@"text%d",i+1]];

                }

            }

        }success:^(AFHTTPRequestOperation *operation,id responseObject) {

            //NSLog(@"成功 %@",responseObject);

            //移除_postProgressView

            [_postProgressViewremoveView];

            

           WebInfo *webInfo = [[WebInfoalloc]initWithDictionary:responseObject];

           WebViewController *webViewController = [[WebViewControlleralloc]initWithWebInfo:webInfowebViewType:WEBVIEW_TYPE_POST];

           UINavigationController *navigationController =[[UINavigationControlleralloc]initWithRootViewController:webViewController];

            [selfpresentViewController:navigationControlleranimated:YEScompletion:^{

               //删除所有

                [selfupdateImageInfo:nilupdateType:UPDATETYPE_FOR_DELETE_ALL_OBJECTSindex:0];

            }];

        }failure:^(AFHTTPRequestOperation *operation,NSError *error) {

           NSLog(@"失败 %@",error);

            //移除_postProgressView

            [_postProgressViewremoveView];

        }];

        //添加上传进度block

        [uploadOperationsetUploadProgressBlock:^(NSUInteger bytesWritten,longlong totalBytesWritten,longlong totalBytesExpectedToWrite) {

             //NSLog(@"下载进度---------%.2f%c",(double)totalBytesWritten/totalBytesExpectedToWrite*100,'%');

            //_postProgressView更新进度

            [_postProgressViewupdateWithValue:(double)totalBytesWritten/totalBytesExpectedToWrite];

        }];

    

    }

}


//展示进度视图

-(void)showPostProgressView

{

    if (!_postProgressView) {

       _postProgressView = [[PostProgressViewalloc]initWithFrame:self.view.frame];

    }

    [_postProgressViewshowInView:self.view];

}


//获得当前的时间戳

- (NSString *)getCurrentDateString

{

    NSTimeZone *zone = [NSTimeZonesystemTimeZone];

   NSTimeInterval delta = [zonesecondsFromGMTForDate:[NSDatedate]];

    NSString *string = [NSStringstringWithFormat:@"%f",[[NSDatedate]timeIntervalSince1970] + delta];

    NSString *dateString = [[stringcomponentsSeparatedByString:@"."]objectAtIndex:0];

   return dateString;

}


/*****************************数据库的运用***************************/


//保存草稿方法

-(void)saveDraft

{

   //标题

    NSString *title =_editView.titleView.text;

   if ([UIUtilsisBlankString:title]) {

        title =@"";

    }

    //图片数量

   int imageCount = (int)_imageInfoArray.count;

    //描述数组的字符串

    NSMutableArray *textArray = [[NSMutableArrayalloc]init];

   for (ImageInfo *imageInfoin_imageInfoArray) {

       NSString *text = imageInfo.text;

       if ([UIUtilsisBlankString:text]) {

            text =@"";

        }

        [textArrayaddObject:text];

    }

    //把数组转换为字符串

   NSError *error;

    NSData *textData = [NSJSONSerializationdataWithJSONObject:textArrayoptions:NSJSONWritingPrettyPrintederror:&error];

    NSString *textString = [[NSStringalloc]initWithData:textDataencoding:NSUTF8StringEncoding];

    //当前时间

   NSDate *date = [NSDatedate];

    NSDateFormatter *formatter = [[NSDateFormatteralloc]init];

    NSTimeZone *zone = [NSTimeZonelocalTimeZone];

   NSLog(@"%@",zone);

    [formattersetDateFormat:@"MMddHH"];

   NSString *dateString = [formatterstringFromDate:date];

    

    

   BOOL result = [FMDBToolinsertOnDB:_dbwithTableName:Table_NameandTitle:titleimageCount:imageCounttextString:textStringdateline:dateString];

   if (result) {

       NSLog(@"插入数据成功");

        

        //获取最新一条数据的id

       int draftId = (int)[_dblastInsertRowId];

        //存储图片到磁盘

        [selfsaveImagesWithDraftId:draftId];

        

    }else{

       NSLog(@"插入数据失败");

    }

}


//存储图片到磁盘

-(void)saveImagesWithDraftId:(int)draftId

{

    NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

   NSString *docPath = [pathslastObject];

    NSString *draftPath = [docPathstringByAppendingPathComponent:[NSStringstringWithFormat:@"Draft/draft%d",draftId]];

    //判断文件夹路径是否存在 如果不存在 创建文件夹

    if (![[NSFileManagerdefaultManager]fileExistsAtPath:draftPath]) {

        [[NSFileManagerdefaultManager]createDirectoryAtPath:draftPathwithIntermediateDirectories:YESattributes:nilerror:nil];

    }

   for (int i=0; i<_imageInfoArray.count; i++) {

       ImageInfo *imageInfo =_imageInfoArray[i];

       UIImage *image = imageInfo.image;

       NSData *data =UIImageJPEGRepresentation(image,1.0f);

        NSString *imagePath = [draftPathstringByAppendingPathComponent:[NSStringstringWithFormat:@"image %d.jpg",i]];

        [datawriteToFile:imagePathatomically:YES];

    }

}


//创建数据库中的表

-(void)createTabel

{

    BOOL result = [FMDBToolcreateTableOnDB:_dbwithTableName:Table_Name];

   if (result) {

       NSLog(@"建表成功");

    }else{

       NSLog(@"建表失败");

    }

    [_dbclose];

}


/*************************添加内容视图**************************/

#pragma mark 添加内容视图

//添加主视图

-(void)addMainView

{

    _mainView = [[MainViewalloc]initWithFrame:self.view.frame];

    _mainView.delegate =self;

    [self.viewaddSubview:_mainView];

}


//添加编辑视图

-(void)addEditView

{

    _editView=[[EditViewalloc]initWithFrame:self.view.frame];

    _editView.delegate =self;

    _editView.layer.transform = CATransform3DMakeScale(0.8,0.8,1.0);

    _editView.layer.opacity=0.5;


}


//把状态栏设置为白色

-(void)setStatusBarColor

{

    //设置状态栏为白色

    [[UIApplicationsharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];

}


/*********************动画效果*************************/

#pragma mark  动画效果

//向前放大动画效果

-(void)scaleAnimationForward

{

    [UIViewanimateWithDuration:0.2animations:^{

        _mainView.layer.transform = CATransform3DMakeScale(1,1,1);

    } completion:nil];

}

//切换到EditView时的动画效果

-(void)showEditViewAnimation

{

    [UIViewanimateWithDuration:0.3animations:^{

        _mainView.layer.transform = CATransform3DMakeScale(0.8,0.8,1.0);

       _mainView.layer.opacity =0.5;

    }completion:^(BOOL finished) {

        //移除_mainView

       if (_mainView.superview) {

            [_mainViewremoveFromSuperview];

        }

        //添加_editView

       if (!_editView.superview) {

            [self.viewaddSubview:_editView];

        }

        

        [UIViewanimateWithDuration:0.3animations:^{

           _editView.layer.transform =CATransform3DMakeScale(1.0,1.0,1.0);

           _editView.layer.opacity =1.0;

        }completion:nil];

    }];

}


//切换到_mainView的动画效果

-(void)showMainViewAnimation

{

    [UIViewanimateWithDuration:0.3animations:^{

        _editView.layer.transform = CATransform3DMakeScale(0.8,0.8,1.0);

       _editView.layer.opacity =0.5;

    }completion:^(BOOL finished) {

       if (_editView.superview) {

            [_editViewremoveFromSuperview];

        }

       if (!_mainView.superview) {

            [self.viewaddSubview:_mainView];

        }

        [UIViewanimateWithDuration:0.3animations:^{

           _mainView.layer.transform =CATransform3DMakeScale(1.0,1.0,1.0);

           _mainView.layer.opacity =1.0;

        }completion:nil];

        

    }];


}


//向后缩小动画效果

-(void)scaleAnimationBackward

{

    [UIViewanimateWithDuration:0.2animations:^{

        _mainView.layer.transform = CATransform3DMakeScale(0.8,0.8,1);

    } completion:nil];

}

/***************************按钮点击方法****************************/

#pragma mark 按钮点击方法

//设置按钮被点击

-(void)setButtonPressed

{

    //向后缩小动画效果

    [selfscaleAnimationBackward];

   

    //设置按钮被点击

    SetViewController *setViewController = [[SetViewControlleralloc]init];

   UINavigationController *navSetViewController = [[UINavigationControlleralloc]initWithRootViewController:setViewController];

    [selfpresentViewController:navSetViewControlleranimated:YEScompletion:nil];

}


//我的旅拍按钮被点击

-(void)myListButtonPressed

{

    //向后缩小动画效果

    [selfscaleAnimationBackward];

    

    MylistViewController *mylistViewController = [[MylistViewControlleralloc]init];

   UINavigationController *navMylistVC = [[UINavigationControlleralloc]initWithRootViewController:mylistViewController];

    [selfpresentViewController:navMylistVCanimated:YEScompletion:nil];

}


//本地草稿按钮被点击

-(void)localDraftButtonPressed

{

    //向后缩小动画效果

    [selfscaleAnimationBackward];

    

    LocalDraftViewController *localDraftVC = [[LocalDraftViewControlleralloc]init];

   UINavigationController *navLocaldraftVC = [[UINavigationControlleralloc]initWithRootViewController:localDraftVC];

    [selfpresentViewController:navLocaldraftVCanimated:YEScompletion:nil];

}


//拍照按钮被点击

-(void)cameraButtonPressed

{

     

    if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIImagePickerController *imagePicker = [[UIImagePickerControlleralloc]init];

        imagePicker.delegate =self;

        imagePicker.sourceType =UIImagePickerControllerSourceTypeCamera;

        [selfpresentViewController:imagePickeranimated:YEScompletion:nil];

    }else{

       UIAlertView *alertView = [[UIAlertViewalloc]

                               initWithTitle:@"您手机没有拍照功能"

                               message:nil

                               delegate:nil

                               cancelButtonTitle:@"知道了"

                               otherButtonTitles:nil];

        [alertViewshow];

    }


}


//相册按钮被点击

-(void)libraryButtonpressed

{

    

    if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

        UIImagePickerController *imagePicker = [[UIImagePickerControlleralloc]init];

        imagePicker.delegate =self;

        imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;

        [selfpresentViewController:imagePickeranimated:YEScompletion:nil];

    }else{

       UIAlertView *alertView = [[UIAlertViewalloc]

                               initWithTitle:@"您手机没有相册功能"

                               message:nil

                               delegate:nil

                               cancelButtonTitle:@"知道了"

                               otherButtonTitles:nil];

        [alertViewshow];

    }


}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

/*******************MainViewDelegate的代理方法**********************/

#pragma mark MainViewDelegate

//设置按钮被点击

-(void)mainViewSetButtonPressed

{

    [selfsetButtonPressed];

}


//拍照按钮被点击

-(void)mainViewCameraButtonPressed

{

    _updateType =UPDATETYPE_FOR_ADD_ONE_OBJECT;

    [selfcameraButtonPressed];

}


//相册按钮被点击

-(void)mainViewLibraryButtonpressed

{

    _updateType =UPDATETYPE_FOR_ADD_ONE_OBJECT;

    [selflibraryButtonpressed];

}


//我的旅拍按钮被点击

-(void)mainViewMyListButtonPressed

{

    [selfmyListButtonPressed];

}


//本地草稿按钮被点击

-(void)mainViewLocalDraftButtonPressed

{

    [selflocalDraftButtonPressed];

}

/**********************EditViewDelegate代理方法*******************/

#pragma mark EditViewDelegate

-(void)editViewBackButtonPressed

{

   UIAlertView *alertView = [[UIAlertViewalloc]

                             initWithTitle:@"是否保存本地草稿"

                             message:@"保存本地草稿后可以再次编辑并且上传"

                             delegate:self

                             cancelButtonTitle:@"不保存"

                             otherButtonTitles:@"保存",nil];

    [alertViewshow];


    

    

    //切换到_mainView的动画效果

    //[self showMainViewAnimation];

    

}

-(void)editViewUploadButtonPressed

{

    //上传多张图片

    [selfuploadImages];

}


-(void)editViewCameraButtonPressed

{

    _updateType =UPDATETYPE_FOR_ADD_ONE_OBJECT;

    [selfcameraButtonPressed];

}


-(void)editViewLibraryButtonPressed

{

    _updateType =UPDATETYPE_FOR_ADD_ONE_OBJECT;

    [selflibraryButtonpressed];

}


-(void)editViewActionSheetCameraButtonPressed:(int)index

{

   _editIndex = index;

    _updateType =UPDATETYPE_FOR_EDIT_ONE_OBJECT;

    [selfcameraButtonPressed];

}


-(void)editViewActionSheetLibraryButtonPressed:(int)index

{

   _editIndex = index;

    _updateType =UPDATETYPE_FOR_EDIT_ONE_OBJECT;

    [selflibraryButtonpressed];

}


//删除一个ImageInfo对象

-(void)editViewDeleteImageInfoAtIndex:(int)index

{

    [selfupdateImageInfo:nilupdateType:UPDATETYPE_FOR_DELETE_ONE_OBJECTindex:index];

//    [_imageInfoArray removeObjectAtIndex:index];

//    [_editView reloadEditViewWithArray:_imageInfoArray andUpdateType:updateType];

}


-(void)editViewInputTextViewSaveButtonPressedWithImageInfo:(ImageInfo *)imageInfo andIndex:(int)index

{

   NSLog(@"text %@ index %d",imageInfo.text,index);

    [selfupdateImageInfo:imageInfoupdateType:UPDATETYPE_FOR_EDIT_ONE_OBJECTindex:index];

}


/***************UIImagePickerControllerDelegate代理方法*****************/

#pragma mark UIImagePickerControllerDelegate

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

    //获取原始图片

    UIImage *originalImage = [infoobjectForKey:@"UIImagePickerControllerOriginalImage"];

   ImageInfo *imageInfo;

    if (_updateType ==UPDATETYPE_FOR_EDIT_ONE_OBJECT) {

       ImageInfo *beforeImageInfo =_imageInfoArray[_editIndex];

        imageInfo = [[ImageInfoalloc]initWithImage:originalImageandText:beforeImageInfo.text];

    }else{

        imageInfo = [[ImageInfoalloc]initWithImage:originalImageandText:nil];

    }

    


//    //更新

//    [self updateImageInfo:imageInfo updateType:_updateType index:_editIndex];

//    

//    

//    //设置状态栏为白色

//    [self setStatusBarColor];

//    [self dismissViewControllerAnimated:YES completion:^{

//        _editView.titleView.text = @"";

//        [self showEditViewAnimation];

//    }];

    

    //设置状态栏为白色

    [selfsetStatusBarColor];

    [selfdismissViewControllerAnimated:YEScompletion:^{

       //更新

        [selfupdateImageInfo:imageInfoupdateType:_updateTypeindex:_editIndex];

    }];


}


-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

{

    //设置状态栏为白色

    [selfsetStatusBarColor];

    [selfdismissViewControllerAnimated:YEScompletion:nil];

}


/**********************UIAlertViewDelegate的代理方法***********************/

#pragma mark UIAlertViewDelegate

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

   if (buttonIndex ==1) {

        

       if (!_db) {

            

           //创建数据库

           _db = [FMDBToolcreateDataBase];

        }

       if ([_dbopen]) {

           //创建数据库中的表

            [selfcreateTabel];

        }

       if ([_dbopen]) {

           //保存草稿

            [selfsaveDraft];

        }

        

    }

    [selfupdateImageInfo:nilupdateType:UPDATETYPE_FOR_DELETE_ALL_OBJECTSindex:0];


}


@end




//

//  MainView.m

//  我的旅拍1.0

//

//  Created by  on 15/7/7.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "MainView.h"

#import "UIUtils.h"

#import "SetViewController.h"

#import "MylistViewController.h"

#import "LocalDraftViewController.h"

@interface MainView ()

{

   UIImageView *_backgroundImageView;//背景视图

   UIButton *_setButton;//设置按钮

   UIButton *_cameraButton;//拍照按钮

   UIButton *_libraryButton;//相册按钮

   UIButton *_myListButton;//我的旅拍按钮

   UIButton *_localDraftButton;//本地草稿按钮

}

@end


@implementation MainView


-(id)initWithFrame:(CGRect)frame

{

   self = [superinitWithFrame:frame];

   if (self) {

       //添加内容视图

        [selfaddContentView];

    }

    return self;

}

//添加内容视图

-(void)addContentView

{

    //添加背景视图

    [selfaddBackgroundImageView];

    //添加设置按钮

    [selfaddSetButton];

    //添加拍照和相册按钮

    [selfaddCameraAndLibraryButton];

    //添加我的旅拍和本地草稿按钮

    [selfaddMyListAndLocalDraftButton];

}

/************************添加UI视图*************************/

#pragma mark  添加UI视图


-(void)addBackgroundImageView

{

    //添加背景视图

    _backgroundImageView = [[UIImageViewalloc]initWithFrame:self.frame];

    [_backgroundImageViewsetImage:[UIImageimageNamed:@"lp_main_background.png"]];

    _backgroundImageView.userInteractionEnabled =YES;

    [selfaddSubview:_backgroundImageView];

    

    //添加icon视图

   UIImage *iconImage = [UIImageimageNamed:@"lp_main_icon.png"];

   UIImageView *iconImageView = [[UIImageViewalloc]initWithFrame:CGRectMake(([UIUtilsgetWindowWidth]-iconImage.size.width)/2,60, iconImage.size.width, iconImage.size.height)];

    [iconImageViewsetImage:iconImage];

    [_backgroundImageViewaddSubview:iconImageView];

    

}


-(void)addSetButton

{

    //添加设置按钮

   UIImage *setButtonImage = [UIImageimageNamed:@"lp_set_button.png"];

    _setButton = [UIButtonbuttonWithType:UIButtonTypeCustom];

    [_setButtonaddTarget:selfaction:@selector(setButtonPressed)forControlEvents:UIControlEventTouchUpInside];

   _setButton.frame =CGRectMake([UIUtilsgetWindowWidth]-setButtonImage.size.width-10,25, setButtonImage.size.width, setButtonImage.size.height);

    [_setButtonsetBackgroundImage:setButtonImageforState:UIControlStateNormal];

    [_backgroundImageViewaddSubview:_setButton];

}


-(void)addCameraAndLibraryButton

{

    //添加拍照按钮

    UIImage *cameraButtonImage = [UIImageimageNamed:@"lp_bigCameraButtonImage_normal.png"];

    _cameraButton = [UIButtonbuttonWithType:UIButtonTypeCustom];

   _cameraButton.frame =CGRectMake(([UIUtilsgetWindowWidth]-cameraButtonImage.size.width*2)/3, ([UIUtilsgetWindowHeight]-cameraButtonImage.size.height)/2, cameraButtonImage.size.width, cameraButtonImage.size.height);

    [_cameraButtonaddTarget:selfaction:@selector(cameraButtonPressed)forControlEvents:UIControlEventTouchUpInside];

    [_cameraButtonsetBackgroundImage:cameraButtonImageforState:UIControlStateNormal];

    [_backgroundImageViewaddSubview:_cameraButton];

    

    //添加相册按钮

    UIImage *libraryButtonImage = [UIImageimageNamed:@"lp_bigLibraryButtonImage_normal.png"];

    _libraryButton = [UIButtonbuttonWithType:UIButtonTypeCustom];

   _libraryButton.frame =CGRectMake(CGRectGetMaxX(_cameraButton.frame)+([UIUtilsgetWindowWidth]-cameraButtonImage.size.width*2)/3, ([UIUtilsgetWindowHeight]-cameraButtonImage.size.height)/2, libraryButtonImage.size.width, libraryButtonImage.size.height);

    [_libraryButtonaddTarget:selfaction:@selector(libraryButtonpressed)forControlEvents:UIControlEventTouchUpInside];

    [_libraryButtonsetBackgroundImage:libraryButtonImageforState:UIControlStateNormal];

    [_backgroundImageViewaddSubview:_libraryButton];

    

}


-(void)addMyListAndLocalDraftButton

{

    //添加我的旅拍按钮

   UIImage *myListButtonImageNormal = [UIImageimageNamed:@"lp_mylist_button_normal.png"];

   UIImage *mylistButtonImageHighlight = [UIImageimageNamed:@"lp_mylist_button_highlight.png"];

    _myListButton = [UIButtonbuttonWithType:UIButtonTypeCustom];

   _myListButton.frame =CGRectMake(0, [UIUtilsgetWindowHeight]-myListButtonImageNormal.size.height/myListButtonImageNormal.size.width*[UIUtilsgetWindowWidth]/2, [UIUtilsgetWindowWidth]/2, myListButtonImageNormal.size.height/myListButtonImageNormal.size.width*[UIUtilsgetWindowWidth]/2);

    [_myListButtonaddTarget:selfaction:@selector(myListButtonPressed)forControlEvents:UIControlEventTouchUpInside];

    [_myListButtonsetBackgroundImage:myListButtonImageNormalforState:UIControlStateNormal];

    [_myListButtonsetBackgroundImage:mylistButtonImageHighlightforState:UIControlStateHighlighted];

    [_backgroundImageViewaddSubview:_myListButton];

    

    //添加本地草稿按钮

   UIImage *localDraftButtonImageNormal = [UIImageimageNamed:@"lp_draft_button_normal.png"];

   UIImage *localDraftButtonImageHighlight = [UIImageimageNamed:@"lp_draft_button_highlight.png"];

    _localDraftButton = [UIButtonbuttonWithType:UIButtonTypeCustom];

   _localDraftButton.frame =CGRectMake([UIUtilsgetWindowWidth]/2, [UIUtilsgetWindowHeight]-localDraftButtonImageNormal.size.height/localDraftButtonImageNormal.size.width*[UIUtilsgetWindowWidth]/2, [UIUtilsgetWindowWidth]/2, localDraftButtonImageNormal.size.height/localDraftButtonImageNormal.size.width*[UIUtilsgetWindowWidth]/2);

    [_localDraftButtonaddTarget:selfaction:@selector(localDraftButtonPressed)forControlEvents:UIControlEventTouchUpInside];

    [_localDraftButtonsetBackgroundImage:localDraftButtonImageNormalforState:UIControlStateNormal];

    [_localDraftButtonsetBackgroundImage:localDraftButtonImageHighlightforState:UIControlStateHighlighted];

    [_backgroundImageViewaddSubview:_localDraftButton];

    

}

/************************按钮点击方法***************************/

#pragma mark 按钮点击方法

//设置按钮被点击

-(void)setButtonPressed

{

    

   if (self.delegate&&[self.delegaterespondsToSelector:@selector(mainViewSetButtonPressed)]) {

        [self.delegatemainViewSetButtonPressed];

    }

}

//拍照按钮被点击

-(void)cameraButtonPressed

{

    

   if (self.delegate&&[self.delegaterespondsToSelector:@selector(mainViewCameraButtonPressed)]) {

        [self.delegatemainViewCameraButtonPressed];

    }

}

//相册按钮被点击

-(void)libraryButtonpressed

{

   

   if (self.delegate&&[self.delegaterespondsToSelector:@selector(mainViewLibraryButtonpressed)]) {

        [self.delegatemainViewLibraryButtonpressed];

    }

}

//我的旅拍按钮被点击

-(void)myListButtonPressed

{

    

   if (self.delegate&&[self.delegaterespondsToSelector:@selector(mainViewMyListButtonPressed)]) {

        [self.delegatemainViewMyListButtonPressed];

    }

}

//本地草稿按钮被点击

-(void)localDraftButtonPressed

{

    

   if (self.delegate&&[self.delegaterespondsToSelector:@selector(mainViewLocalDraftButtonPressed)]) {

        [self.delegatemainViewLocalDraftButtonPressed];

    }

}

@end




//

//  EditView.m

//  我的旅拍1.0

//

//  Created by  on 15/7/7.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "EditView.h"


#import "UIUtils.h"

#import "EditViewCell.h"

#import "ImageInfo.h"

#import "InputTextView.h"


#define MARGIN_WIDTH 20

#define TITLE_VIEW_HEIGHT 40

#define ADD_BUTTON_HEIGHT 60

#define TITLE_LARGE_COUNT 30//标题的字数限制

#define TITLECOUNTLABEL_WIDTH 35//标题剩余字数标签的宽度

#define TITLECOUNTLABEL_HEIGHT 40//标题剩余字数标签的高度


@interface EditView ()<UITableViewDataSource,UITableViewDelegate,EditViewCellDelegate,UIActionSheetDelegate,UITextViewDelegate,InputTextViewDelegate>

{

    UIImageView *_topView;//顶部视图

    UIButton *_backButton;//返回按钮

    UIButton *_uploadButton;//上传按钮

    UITextView *_titleView;//标题视图

    UILabel *_titleViewPlaceHolderLabel;//标题视图中显示默认文字的文字视图

    

    UIView *_editTitleOpaqueView;//编辑标题视图的遮盖视图

    UITextView *_editTitleView;//编辑标题视图

    UILabel *_titleCountLabel;//显示标题剩余字数标签

   int _titleCount;//标题剩余的字数

    

    UIView *_bottomView;//底部视图

    UIButton *_cameraButton;//拍照按钮

    UIButton *_libraryButton;//相册按钮

    UITableView *_tableView;//表视图

    NSArray *_imageInfoArray;//存放_imageInfoArray对象的数组

   int _editIndex;//被编辑的索引

    

}

@end


@implementation EditView


-(id)initWithFrame:(CGRect)frame

{

   self = [super initWithFrame:frame];

   if (self) {

        [self addContentView];

    }

    return self;

}


//array刷新EditView显示的内容

-(void)reloadEditViewWithArray:(NSArray *)array andUpdateType:(UpdateType)updateType

{

    _imageInfoArray = array;

    [_tableView reloadData];

    

   if ([UIUtils isBlankString:_titleView.text]) {

       if (!_titleViewPlaceHolderLabel.superview) {

            [_titleView addSubview:_titleViewPlaceHolderLabel];

        }

    }else{

       if (_titleViewPlaceHolderLabel.superview) {

            [_titleViewPlaceHolderLabel removeFromSuperview];

        }

    }

    

   if ((updateType == UPDATETYPE_FOR_ADD_MORE_OBJECTS)||(updateType == UPDATETYPE_FOR_ADD_ONE_OBJECT)) {

        //加多图片,自动移动把最新图片显示到屏幕上

       if ((_tableView.contentSize.height-_tableView.frame.size.height)>0) {

            [_tableView setContentOffset:CGPointMake(0, _tableView.contentSize.height-_tableView.frame.size.height) animated:YES];

        }

    }

   

}


//添加内容视图

-(void)addContentView

{

    [self setBackgroundColor:LIGHT_WHITE_COLOR];

    //添加顶部紫色视图

    [self addTopView];

    //添加标题视图

    [self addTitleView];

    //添加表视图

    [self addTableView];

    //添加底部视图

    [self addBottomView];

}

/**************************添加UI视图****************************/

#pragma mark 添加UI视图

//添加顶部紫色视图

-(void)addTopView

{

    _topView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, [UIUtils getWindowWidth],44+20)];

    _topView.userInteractionEnabled =YES;

    [_topView setImage:[UIImage imageNamed:@"lp_nav_purple.png"]];

    [self addSubview:_topView];

    

    //添加返回按钮

    UIImage *backButtonImage = [UIImage imageNamed:@"lp_nav_goback.png"];

    _backButton = [UIButton buttonWithType:UIButtonTypeCustom];

    [_backButton addTarget:self action:@selector(backButtonPressed) forControlEvents:UIControlEventTouchUpInside];

    [_backButton setBackgroundImage:backButtonImage forState:UIControlStateNormal];

    [_backButton setFrame:CGRectMake(10,20+5, backButtonImage.size.width, backButtonImage.size.height)];

    [_topView addSubview:_backButton];

    

    //添加上传按钮

    UIImage *uploadImageNormal = [UIImage imageNamed:@"lp_upload_button_normal.png"];

    UIImage *uploadImageHighlight = [UIImage imageNamed:@"lp_upload_button_highlight.png"];

    _uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];

    [_uploadButton addTarget:self action:@selector(uploadButtonPressed) forControlEvents:UIControlEventTouchUpInside];

    [_uploadButton setBackgroundImage:uploadImageNormal forState:UIControlStateNormal];

    [_uploadButton setBackgroundImage:uploadImageHighlight forState:UIControlStateHighlighted];

    [_uploadButton setFrame:CGRectMake([UIUtils getWindowWidth]-uploadImageNormal.size.width-10,20+5, uploadImageNormal.size.width, uploadImageNormal.size.height)];

    [_topView addSubview:_uploadButton];

}

//添加标题视图

-(void)addTitleView

{

    //添加标题视图

    _titleView = [[UITextView alloc] initWithFrame:CGRectMake(MARGIN_WIDTH, CGRectGetMaxY(_topView.frame)+5, [UIUtils getWindowWidth]-MARGIN_WIDTH*2, TITLE_VIEW_HEIGHT)];

    //_titleView添加一个点击手势

    _titleView.font = [UIFont systemFontOfSize:20];

    UITapGestureRecognizer *tapTitleViewGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTitleView)];

    [_titleView addGestureRecognizer:tapTitleViewGesture];

    [self addSubview:_titleView];

    

    //不能滚动

    _titleView.scrollEnabled =NO;

    //不能选择

   if (isIos7System) {

        [_titleView setSelectable:NO];

    }

    //不能编辑

    _titleView.editable =NO;

    

    //标题视图中显示默认文字的文字视图

    _titleViewPlaceHolderLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, _titleView.frame.size.width, _titleView.frame.size.height)];

    [_titleViewPlaceHolderLabel setBackgroundColor:[UIColor clearColor]];

    [_titleViewPlaceHolderLabel setTextColor:[UIColor blackColor]];

    [_titleViewPlaceHolderLabel setTextAlignment:NSTextAlignmentCenter];

    [_titleViewPlaceHolderLabel setText:@"输入标题"];

    [_titleView addSubview:_titleViewPlaceHolderLabel];

  

}

//添加表视图

-(void)addTableView

{

    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_titleView.frame)+5, [UIUtils getWindowWidth], [UIUtils getWindowHeight]-(CGRectGetMaxY(_titleView.frame)+5)-ADD_BUTTON_HEIGHT-10) style:UITableViewStylePlain];

    _tableView.dataSource =self;

    _tableView.delegate =self;

    _tableView.separatorColor = [UIColor redColor];

    [_tableView setBackgroundColor:LIGHT_WHITE_COLOR];

    [self addSubview:_tableView];

}


//添加底部视图

-(void)addBottomView

{

    _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIUtils getWindowHeight]-ADD_BUTTON_HEIGHT-10, [UIUtils getWindowHeight], ADD_BUTTON_HEIGHT+10)];

    _bottomView.backgroundColor = LIGHT_WHITE_COLOR;

    [self addSubview:_bottomView];

    

    //添加拍照按钮

    

    UIImage *cameraButtonImageNormal = [UIImage imageNamed:@"lp_cameraButtonImage_normal.png"];

    UIImage *cameraButtonImageHighlight = [UIImage imageNamed:@"lp_cameraButtonImage_highlight.png"];

    _cameraButton = [UIButton buttonWithType:UIButtonTypeCustom];

    [_cameraButton addTarget:self action:@selector(cameraButtonPressed) forControlEvents:UIControlEventTouchUpInside];

    

    [_cameraButton setFrame:CGRectMake(MARGIN_WIDTH,5, ([UIUtils getWindowWidth]-MARGIN_WIDTH*2-10)/2, ADD_BUTTON_HEIGHT)];

    

    [_cameraButton setBackgroundImage:cameraButtonImageNormal forState:UIControlStateNormal];

    [_cameraButton setBackgroundImage:cameraButtonImageHighlight forState:UIControlStateHighlighted];

    [_bottomView addSubview:_cameraButton];

    

    //添加相册按钮

    

    UIImage *libraryButtonImageNormal = [UIImage imageNamed:@"lp_libraryButtonImage_normal.png"];

    UIImage *libraryButtonImageHighlight = [UIImage imageNamed:@"lp_libraryButtonImage_highlight.png"];

    _libraryButton = [UIButton buttonWithType:UIButtonTypeCustom];

    [_libraryButton addTarget:self action:@selector(libraryButtonPressed) forControlEvents:UIControlEventTouchUpInside];

    [_libraryButton setFrame:CGRectMake(CGRectGetMaxX(_cameraButton.frame)+10,5, ([UIUtils getWindowWidth]-MARGIN_WIDTH*2-10)/2, ADD_BUTTON_HEIGHT)];

    

    [_libraryButton setBackgroundImage:libraryButtonImageNormal forState:UIControlStateNormal];

    [_libraryButton setBackgroundImage:libraryButtonImageHighlight forState:UIControlStateHighlighted];

    [_bottomView addSubview:_libraryButton];

}


/************************常用方法****************************/

#pragma mark  常用方法

//点击_titleView

-(void)tapTitleView

{

    //初始化遮盖视图

   if (!_editTitleOpaqueView) {

        _editTitleOpaqueView = [[UIView alloc] initWithFrame:self.frame];

        

        //给遮盖视图添加点击手势

        UITapGestureRecognizer *tapOpaqueViewGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOpaqueView)];

        [_editTitleOpaqueView addGestureRecognizer:tapOpaqueViewGesture];

        

        [_editTitleOpaqueView setBackgroundColor:[UIColor clearColor]];

    }

   if (!_editTitleOpaqueView.superview) {

        [self addSubview:_editTitleOpaqueView];

        [UIView animateWithDuration:0.3 animations:^{

            [_editTitleOpaqueView setBackgroundColor:LIGHT_OPAQUE_BLACK_COLOR];

        } completion:nil];

    }

    

    //初始化_editTitleView

   if (!_editTitleView) {

        _editTitleView = [[UITextView alloc] initWithFrame:_titleView.frame];

        _editTitleView.backgroundColor=[UIColor whiteColor];

        

        [_editTitleView setDelegate:self];

        _editTitleView.returnKeyType=UIReturnKeyDone;

        _editTitleView.scrollEnabled=NO;

        [_editTitleView setFont:[UIFont systemFontOfSize:20]];

    }

    [_editTitleView setText:_titleView.text];

   if (!_editTitleView.superview) {

        [_editTitleOpaqueView addSubview:_editTitleView];

    }

   if (!_editTitleView.isFirstResponder) {

        [_editTitleView becomeFirstResponder];

    }

    

    //添加显示标题字数标签

   if (!_titleCountLabel) {

        _titleCountLabel = [[UILabel alloc] init];

        [_titleCountLabel setFrame:CGRectMake(CGRectGetMaxX(_editTitleView.frame)-TITLECOUNTLABEL_WIDTH, CGRectGetMaxY(_editTitleView.frame), TITLECOUNTLABEL_WIDTH, TITLECOUNTLABEL_HEIGHT)];

        [_titleCountLabel setBackgroundColor:[UIColor clearColor]];

        [_titleCountLabel setTextAlignment:NSTextAlignmentCenter];

        [_titleCountLabel setFont:[UIFont systemFontOfSize:20]];

    }

    [_titleCountLabel setTextColor:LIGHT_GREEN_COLOR];

    [_titleCountLabel setText:[NSString stringWithFormat:@"%d",(int)(TITLE_LARGE_COUNT-_editTitleView.text.length)]];

   if (!_titleCountLabel.superview) {

        [_editTitleOpaqueView addSubview:_titleCountLabel];

    }

    

}


//点击_editTitleOpaqueView

-(void)tapOpaqueView

{

   if (_titleCount<0) {

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"标题不能超过30个字,把多余的字删除!" message:nil delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles: nil];

        [alertView show];

    }else{

       if (_editTitleOpaqueView.superview) {

            [UIView animateWithDuration:0.3 animations:^{

                [_editTitleOpaqueView setBackgroundColor:[UIColor clearColor]];

            } completion:^(BOOL finished) {

                [_editTitleOpaqueView removeFromSuperview];

            }];

        }

        

       if (![UIUtils isBlankString:_editTitleView.text]) {

           //标题赋予值

            _titleView.text = _editTitleView.text;

           if (_titleViewPlaceHolderLabel.superview) {

                [_titleViewPlaceHolderLabel removeFromSuperview];

            }

        }else{

            [_titleView setText:@""];

           if (!_titleViewPlaceHolderLabel.superview) {

                [_titleView addSubview:_titleViewPlaceHolderLabel];

            }

        }


    }

    

}


/*********************点击按钮方法****************************/

#pragma mark 点击按钮方法

-(void)backButtonPressed

{

   if (self.delegate&&[self.delegate respondsToSelector:@selector(editViewBackButtonPressed)]) {

        //_titleView.text = @"";

        [self.delegate editViewBackButtonPressed];

    }

}

-(void)uploadButtonPressed

{

   if (self.delegate&&[self.delegate respondsToSelector:@selector(editViewUploadButtonPressed)]) {

        [self.delegate editViewUploadButtonPressed];

    }

}

-(void)cameraButtonPressed

{

   if (self.delegate&&[self.delegate respondsToSelector:@selector(editViewCameraButtonPressed)]) {

        [self.delegate editViewCameraButtonPressed];

    }

}

-(void)libraryButtonPressed

{

   if (self.delegate&&[self.delegate respondsToSelector:@selector(editViewLibraryButtonPressed)]) {

        [self.delegate editViewLibraryButtonPressed];

    }

}

/*******************UITableViewDataSource的代理方法*********************/

#pragma mark UITableViewDataSource


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

   return _imageInfoArray.count;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

   static NSString *editViewCellIdentifier =@"editViewCellIdentifier";

    EditViewCell *cell = [tableView dequeueReusableCellWithIdentifier:editViewCellIdentifier];

   if (!cell) {

        cell = [[EditViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:editViewCellIdentifier];

        cell.delegate =self;

    }

    //设置tag

    cell.tag = indexPath.row;

    ImageInfo *imageInfo = _imageInfoArray[indexPath.row];

    [cell setContentView:imageInfo];

   return cell;

}


//删除一行

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

   if (self.delegate&&[self.delegate respondsToSelector:@selector(editViewDeleteImageInfoAtIndex:)]) {

        [self.delegate editViewDeleteImageInfoAtIndex:(int)indexPath.row];

    }

}


/**************************UITableViewDelegate的代理方法*****************/

#pragma mark UITableViewDelegate

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    ImageInfo *imageInfo = _imageInfoArray[indexPath.row];

   return imageInfo.imageAndTextHeight;

}

/*********************EditViewCellDelegate的代理方法*************************/

#pragma mark EditViewCellDelegate

-(void)editViewCellImageViewTapWithIndex:(int)index

{

    //编辑索引赋值

    _editIndex = index;

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"更换照片"

                                                             delegate:self

                                                    cancelButtonTitle:@"取消"

                                               destructiveButtonTitle:nil

                                                    otherButtonTitles:@"拍照",@"从手机相册选择",nil];

    [actionSheet showInView:self];

}


//cell中的文字被点击

-(void)editViewCellTextViewTapWithIndex:(int)index

{

    //_editIndex赋值

    _editIndex = index;

    InputTextView *inputTextView = [[InputTextView alloc] initWithFrame:self.frame];

    inputTextView.delegate =self;

   ImageInfo *imageInfo =_imageInfoArray[index];

    [inputTextViewshowInView:selfwithImageInfo:imageInfo];

}


/*************************UIActionSheetDelegate的代理方法********************/

#pragma mark UIActionSheetDelegate

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

   if (buttonIndex ==0) {

       if (self.delegate&&[self.delegaterespondsToSelector:@selector(editViewActionSheetCameraButtonPressed:)]) {

            [self.delegateeditViewActionSheetCameraButtonPressed:_editIndex];

        }

        

    }elseif (buttonIndex ==1){

       if (self.delegate&&[self.delegaterespondsToSelector:@selector(editViewActionSheetLibraryButtonPressed:)]) {

            [self.delegateeditViewActionSheetLibraryButtonPressed:_editIndex];

        }

    }

}

/**********************UITextViewDelegate的代理方法***********************/

#pragma mark UITextViewDelegate


-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

{

    //当点击键盘上的完成按钮 就执行tapOpaqueView方法

   if ([textisEqualToString:@"\n"]) {

        [self tapOpaqueView];

       returnNO;

    }

    //点击删除键时  range.length1点击其他键时 range.length0

   if (range.length ==1) {

       returnYES;

    }

    //限定editTitleView的字数

    NSMutableString *editTitleViewText = [_editTitleView.text mutableCopy];

    

    [editTitleViewText replaceCharactersInRange:range withString:text];

   return [editTitleViewText length]<TITLE_LARGE_COUNT+9;

    

}


-(void)textViewDidChange:(UITextView *)textView

{

    //计算出title的高度

   int titleHeight =0;

   if (isIos7System) {

        CGFloat fixedWidth = textView.frame.size.width;

        CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];

        titleHeight = newSize.height;

    }else {

        titleHeight = textView.contentSize.height;

    }

    

    //设置_editTitleView _titleView _tableView _titleCountLabelframe

    CGRect frame = _editTitleView.frame;

    frame.size.height = titleHeight;

    [_editTitleView setFrame:frame];

    [_titleView setFrame:frame];

    

    [_tableView setFrame:CGRectMake(0, CGRectGetMaxY(_titleView.frame)+5, [UIUtils getWindowWidth], [UIUtils getWindowHeight]-(CGRectGetMaxY(_titleView.frame)+5)-ADD_BUTTON_HEIGHT-10)];

    [_titleCountLabel setFrame:CGRectMake(CGRectGetMaxX(_editTitleView.frame)-TITLECOUNTLABEL_WIDTH, CGRectGetMaxY(_editTitleView.frame), TITLECOUNTLABEL_WIDTH, TITLECOUNTLABEL_HEIGHT)];

    

    //设置_titleCountLabel里面显示的内容

    _titleCount = (int)(TITLE_LARGE_COUNT-_editTitleView.text.length);

    [_titleCountLabel setText:[NSString stringWithFormat:@"%d",_titleCount]];

   if (_titleCount<0) {

        [_titleCountLabel setTextColor:LIGHT_RED_COLOR];

    }else{

        [_titleCountLabel setTextColor:LIGHT_GREEN_COLOR];

    }

}

/*******************InputTextViewDelegate的代理方法******************/

#pragma mark InputTextViewDelegate

-(void)inputTextViewSaveImageInfo:(ImageInfo *)imageInfo

{

   if (self.delegate&&[self.delegate respondsToSelector:@selector(editViewInputTextViewSaveButtonPressedWithImageInfo:andIndex:)]) {

        [self.delegate editViewInputTextViewSaveButtonPressedWithImageInfo:imageInfo andIndex:_editIndex];

    }

}


@end


//

//  InputTextView.m

//  我的旅拍1.0

//

//  Created by  on 15/7/14.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "InputTextView.h"

#import "Header.h"

#import "UIUtils.h"

#import "ImageInfo.h"


#define KEYBOARD_HEIGHT 216

#define Button_Height 50


@interface InputTextView ()

{

   UIView *_topView;

   UITextView *_textView;

   UIButton *_cancelButton;

   UIButton *_saveButton;

   ImageInfo *_imageInfo;

}

@end


@implementation InputTextView


-(id)initWithFrame:(CGRect)frame

{

   self = [superinitWithFrame:frame];

   if (self) {

        [selfaddContentView];

    }

    return self;

}


//添加内容视图

-(void)addContentView

{

    [selfsetBackgroundColor:[UIColorclearColor]];

    //给自己添加了一个点击手势

   UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(removeInputTextView)];

    [selfaddGestureRecognizer:tapGesture];

    

    //初始化_topView

    _topView = [[UIViewalloc]initWithFrame:CGRectMake(0, -([UIUtilsgetWindowHeight]-KEYBOARD_HEIGHT-60), [UIUtilsgetWindowWidth], [UIUtilsgetWindowHeight]-KEYBOARD_HEIGHT-60)];

    [_topViewsetBackgroundColor:[UIColorwhiteColor]];

    //加圆角

    [_topView.layersetCornerRadius:4.0f];

    [_topView.layersetMasksToBounds:YES];

    [selfaddSubview:_topView];

    

    //初始化_textView

    _textView = [[UITextViewalloc]initWithFrame:CGRectMake(0,0, [UIUtilsgetWindowWidth],CGRectGetHeight(_topView.frame)-Button_Height)];

    //加圆角

    [_textView.layersetCornerRadius:4.0f];

    [_textView.layersetMasksToBounds:YES];

    [_textViewsetFont:[UIFontsystemFontOfSize:18]];

    [_textViewsetBackgroundColor:[UIColorwhiteColor]];

    _textView.keyboardAppearance =UIKeyboardAppearanceLight;

    _textView.keyboardType =UIKeyboardTypeNamePhonePad;

    [_topView addSubview:_textView];

    

    //初始化_cancelButton

    _cancelButton=[UIButtonbuttonWithType:UIButtonTypeCustom];

    [_cancelButtonaddTarget:selfaction:@selector(cancel)forControlEvents:UIControlEventTouchUpInside];

    [_cancelButtonsetFrame:CGRectMake(0,CGRectGetMaxY(_textView.frame), [UIUtilsgetWindowWidth]/2,Button_Height)];

    [_cancelButtonsetBackgroundColor:LIGHT_RED_COLOR];

    [_cancelButton.layersetCornerRadius:4.0f];

    [_cancelButton.layersetMasksToBounds:YES];

    [_cancelButtonsetTitle:@"取消"forState:UIControlStateNormal];

    _cancelButton.showsTouchWhenHighlighted =YES;

    [_topView addSubview:_cancelButton];

    

    //添加确定按钮_saveButton

    _saveButton=[UIButtonbuttonWithType:UIButtonTypeCustom];

    [_saveButtonaddTarget:selfaction:@selector(save)forControlEvents:UIControlEventTouchUpInside];

    [_saveButtonsetFrame:CGRectMake([UIUtilsgetWindowWidth]/2,CGRectGetMaxY(_textView.frame), [UIUtilsgetWindowWidth]/2,Button_Height)];

    [_saveButtonsetBackgroundColor:LIGHT_GREEN_COLOR];

    [_saveButton.layersetCornerRadius:4.0f];

    [_saveButton.layersetMasksToBounds:YES];

    [_saveButtonsetTitle:@"保存"forState:UIControlStateNormal];

    _saveButton.showsTouchWhenHighlighted =YES;

    [_topView addSubview:_saveButton];


}


//显示InputTextView

-(void)showInView:(UIView *)view withImageInfo:(ImageInfo *)imageInfo

{

   _imageInfo = imageInfo;

    [_textViewsetText:imageInfo.text];

    [viewaddSubview:self];

    [_textViewbecomeFirstResponder];

    [UIViewanimateWithDuration:0.3animations:^{

        [selfsetBackgroundColor:LIGHT_BLACK_COLOR];

        //设置_topViewframe

       CGRect topViewFrame =_topView.frame;

        topViewFrame.origin.y =20;

        [_topViewsetFrame:topViewFrame];

        

    } completion:nil];

}


//移除InputTextView

-(void)removeInputTextView

{

    [_textViewresignFirstResponder];

    [UIViewanimateWithDuration:0.3animations:^{

        [selfsetBackgroundColor:[UIColorclearColor]];

        [_topViewsetFrame:CGRectMake(0, -([UIUtilsgetWindowHeight]-KEYBOARD_HEIGHT-60), [UIUtilsgetWindowWidth], [UIUtilsgetWindowHeight]-KEYBOARD_HEIGHT-60)];

        [_topViewsetBackgroundColor:[UIColorwhiteColor]];

    }completion:^(BOOL finished) {

        [selfremoveFromSuperview];

    }];

}


//取消按钮被点击

-(void)cancel

{

    //移除InputTextView

    [selfremoveInputTextView];

}


//保存按钮被点击

-(void)save

{

    //获取新的ImageInfo

   if ([UIUtilsisBlankString:_textView.text]) {

        [_textViewsetText:@""];

    }

    _imageInfo = [[ImageInfoalloc]initWithImage:_imageInfo.imageandText:_textView.text];

    

   if (self.delegate&&[self.delegaterespondsToSelector:@selector(inputTextViewSaveImageInfo:)]) {

        [self.delegateinputTextViewSaveImageInfo:_imageInfo];

    }

    //移除InputTextView

    [selfremoveInputTextView];

}

@end




//

//  PostProgressView.m

//  我的旅拍1.0

//

//  Created by  on 15/7/15.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "PostProgressView.h"

#import "Header.h"

#import "LZMProgressView.h"


@interface PostProgressView ()

{

   LZMProgressView *_progressView;

}

@end


@implementation PostProgressView


-(id)initWithFrame:(CGRect)frame

{

   self = [superinitWithFrame:frame];

   if (self) {

       //添加内容视图

        [selfaddContentView];

    }

    return self;

}

//添加内容视图

-(void)addContentView

{

    _progressView = [[LZMProgressViewalloc]initWithFrame:CGRectMake(0,0,50,50)backColor:[UIColorwhiteColor]progressColor:LIGHT_RED_COLORlineWidth:30];

    _progressView.alpha =0.0f;

    _progressView.center =self.center;

    [selfaddSubview:_progressView];

}


-(void)showInView:(UIView *)view//展示postProgressView

{

    [viewaddSubview:self];

    self.backgroundColor = [UIColorclearColor];

    [UIViewanimateWithDuration:0.3animations:^{

        self.backgroundColor =LIGHT_OPAQUE_BLACK_COLOR;

       _progressView.alpha =1.0f;

       _progressView.frame =CGRectMake(0,0,150, 150);

       _progressView.center =self.center;

    } completion:nil];

}


-(void)removeView//移除postProgressView

{

   [UIViewanimateWithDuration:0.3animations:^{

      self.backgroundColor = [UIColorclearColor];

       _progressView.alpha =0.0f;

      _progressView.frame =CGRectMake(0,0,50, 50);

      _progressView.center =self.center;

   }completion:^(BOOL finished) {

       [selfremoveFromSuperview];

   }];

}


-(void)updateWithValue:(float)progressValue//更新postProgressView进度

{

    [_progressViewupdateWithProgressValue:progressValue];

}


@end


//

//  LZMProgressView.m

//  我的旅拍1.0

//

//  Created by  on 15/7/15.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "LZMProgressView.h"


@interface LZMProgressView ()

{

   UILabel *_progressLabel;

   UIColor *_backColor;

   UIColor *_progressColor;

   CGFloat _lineWidth;

   CGFloat _progress;

}

@end


@implementation LZMProgressView


-(id)initWithFrame:(CGRect)frame

         backColor:(UIColor *)backColor

     progressColor:(UIColor *)progressColor

         lineWidth:(CGFloat)lineWidth

{

   self = [superinitWithFrame:frame];

   if (self) {

       _backColor = backColor;

       _progressColor = progressColor;

       _lineWidth =lineWidth;

        

        [selfsetBackgroundColor:[UIColorcolorWithPatternImage:[UIImageimageNamed:@"lp_progressBackImage.png"]]];

        

       if (!_progressLabel) {

           _progressLabel = [[UILabelalloc]initWithFrame:CGRectMake(0,0,150, 150)];

            _progressLabel.textAlignment =NSTextAlignmentCenter;

            

            [selfaddSubview:_progressLabel];

        }


    }

    return self;

}


- (void)drawRect:(CGRect)rect

{

    UIBezierPath *backCircle = [UIBezierPathbezierPathWithArcCenter:CGPointMake(self.bounds.size.width/2,self.bounds.size.height/2)radius:self.bounds.size.width/2-_lineWidth/2startAngle:(CGFloat)-M_PI_2endAngle:(CGFloat)(1.5 *M_PI) clockwise:YES];

    [_backColor setStroke];

    backCircle.lineWidth =_lineWidth;

    [backCirclestroke];

    

   if (_progress !=0) {

       UIBezierPath *progressCircle = [UIBezierPathbezierPathWithArcCenter:CGPointMake(self.bounds.size.width/2,self.bounds.size.height/2)radius:self.bounds.size.width/2-_lineWidth/2startAngle:(CGFloat)-M_PI_2endAngle:(CGFloat)(-M_PI_2+_progress*2*M_PI)clockwise:YES];

        [_progressColorsetStroke];

        progressCircle.lineWidth =_lineWidth;

        [progressCirclestroke];

    }

}


//更新进度

-(void)updateWithProgressValue:(float)value

{

   _progress = value;

    [_progressLabelsetText:[NSStringstringWithFormat:@"%.f%%",value*100]];

    [selfsetNeedsDisplay];

}


@end




//

//  EditViewCell.m

//  我的旅拍1.0

//

//  Created by  on 15/7/9.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "EditViewCell.h"

#import "ImageInfo.h"

#import "UIUtils.h"

#import "Header.h"


#define MARGIN_WIDTH 20

#define TEXT_FONT


@interface EditViewCell ()

{

    UIImageView *_imageView;//图片视图

    UIImageView *_imageViewOpaqueView;//图片视图的遮盖视图

    UITextView *_textView;//文字视图

    UILabel *_textViewPlaceHolderLabel;//文字视图的占位标签

    

    UILabel *_rightLabel;

    UILabel *_rightLabel1;

    UILabel *_rightLabel2;

}

@end


@implementation EditViewCell


-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

   self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

   if (self) {

       //添加内容视图

        [self addContentView];

    }

    return self;

}


//添加内容视图

-(void)addContentView

{

   self.backgroundColor = LIGHT_WHITE_COLOR;

    _imageView = [[UIImageView alloc] init];

    _imageView.userInteractionEnabled =YES;

    //给图片添加手势

    UITapGestureRecognizer *imageViewTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewTap)];

    [_imageView addGestureRecognizer:imageViewTapGesture];

    [self addSubview:_imageView];

    

    //添加imageView的遮盖视图_imageViewOpaqueView

    UIImage *opaqueImage = [UIImage imageNamed:@"lp_imageopaque.png"];

    _imageViewOpaqueView = [[UIImageView alloc] initWithImage:[opaqueImage stretchableImageWithLeftCapWidth:60 topCapHeight:0]];

    [_imageView addSubview:_imageViewOpaqueView];

    

    //添加文字视图

    _textView = [[UITextView alloc] init];

    [_textView setBackgroundColor:[UIColor whiteColor]];

    [_textView setFont:[UIFont systemFontOfSize:18]];

    [_textView setScrollEnabled:NO];

    [_textView setEditable:NO];

    [self addSubview:_textView];

    

    //给文字视图添加点击手势

    UITapGestureRecognizer *textViewTapGestre = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(textViewTap)];

    [_textView addGestureRecognizer:textViewTapGestre];

    

    //添加文字视图的占位标签

    _textViewPlaceHolderLabel = [[UILabel alloc] initWithFrame:CGRectMake(5,5,200, 30)];

    [_textViewPlaceHolderLabel setBackgroundColor:[UIColor clearColor]];

    [_textViewPlaceHolderLabel setTextColor:[UIColor lightGrayColor]];

    _textViewPlaceHolderLabel.text =@"点击添加描述...";

    

    

    

    _rightLabel=[[UILabel alloc] initWithFrame:CGRectMake([UIUtils getWindowWidth]-MARGIN_WIDTH+2,20,16, 20)];

    _rightLabel.text=@"";

    _rightLabel.textAlignment=NSTextAlignmentCenter;

    [self addSubview:_rightLabel];

    _rightLabel1=[[UILabel alloc] initWithFrame:CGRectMake([UIUtils getWindowWidth]-MARGIN_WIDTH+2,40,16, 20)];

    

    _rightLabel1.textAlignment=NSTextAlignmentCenter;

    [self addSubview:_rightLabel1];

    _rightLabel2=[[UILabel alloc] initWithFrame:CGRectMake([UIUtils getWindowWidth]-MARGIN_WIDTH+2,60,16, 20)];

    _rightLabel2.text=@"";

    _rightLabel2.textAlignment=NSTextAlignmentCenter;

    [self addSubview:_rightLabel2];


}


//点击图片

-(void)imageViewTap

{

   NSLog(@"%d",(int)self.tag);

   if (self.delegate&&[self.delegaterespondsToSelector:@selector(editViewCellImageViewTapWithIndex:)]) {

        [self.delegateeditViewCellImageViewTapWithIndex:(int)self.tag];

    }

}


//点击文字

-(void)textViewTap

{

   if (self.delegate&&[self.delegaterespondsToSelector:@selector(editViewCellTextViewTapWithIndex:)]) {

        [self.delegateeditViewCellTextViewTapWithIndex:(int)self.tag];

    }

}

//设置内容视图中显示的内容

-(void)setContentView:(ImageInfo *)imageInfo

{

    [_imageViewsetImage:imageInfo.image];

    [_imageViewsetFrame:CGRectMake(MARGIN_WIDTH,0, [UIUtilsgetWindowWidth]-MARGIN_WIDTH*2, imageInfo.imageHeight)];

    _rightLabel1.text=[NSStringstringWithFormat:@"%d",self.tag+1];

    

   //设置

    [_imageViewOpaqueViewsetFrame:CGRectMake(0,_imageView.frame.size.height-9,CGRectGetWidth(_imageView.frame),9)];

    

    //设置_textView的显示内容和frame

    [_textViewsetText:imageInfo.text];

    [_textViewsetFrame:CGRectMake(MARGIN_WIDTH, imageInfo.imageHeight,CGRectGetWidth(_imageView.frame), imageInfo.textHeight)];

    

    //根据imageInfotext内容判断文字视图的占位标签是否显示

   if (imageInfo.text.length ==0) {

       if (!_textViewPlaceHolderLabel.superview) {

            [_textView addSubview:_textViewPlaceHolderLabel];

        }

    }else{

       if (_textViewPlaceHolderLabel.superview) {

            [_textViewPlaceHolderLabel removeFromSuperview];

        }

    }

}

@end




//

//  MyListCell.m

//  我的旅拍1.0

//

//  Created by  on 15/7/15.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "MyListCell.h"

#import "UIUtils.h"

#import "Header.h"

#import "WebInfo.h"

#import "UIImageView+WebCache.h"


@interface MyListCell ()

{

   UILabel *_dayLabel;

   UILabel *_monthLabel;

   UILabel *_yearLabel;

   UILabel *_titleLabel;

   UIImageView *_imageView;

   UILabel *_viewCountLabel;

}

@end


@implementation MyListCell


-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

   self = [superinitWithStyle:stylereuseIdentifier:reuseIdentifier];

   if (self) {

        [selfaddContentView];

    }

    return self;

}


-(void)addContentView

{

    //添加天标签

    _dayLabel = [[UILabelalloc]initWithFrame:CGRectMake(5,1,30,30)];

    [_dayLabelsetTextAlignment:NSTextAlignmentCenter];

    [_dayLabelsetFont:[UIFontsystemFontOfSize:26]];

    [selfaddSubview:_dayLabel];

    

    //添加月标签

    _monthLabel = [[UILabelalloc]initWithFrame:CGRectMake(CGRectGetMaxX(_dayLabel.frame),9,50,20)];

    [_monthLabelsetTextAlignment:NSTextAlignmentCenter];

    [_monthLabelsetFont:[UIFontsystemFontOfSize:17]];

    [selfaddSubview:_monthLabel];


    //添加年标签

    _yearLabel = [[UILabelalloc]initWithFrame:CGRectMake(CGRectGetMaxX(_monthLabel.frame),16,30, 10)];

    [_yearLabelsetTextAlignment:NSTextAlignmentCenter];

    [_yearLabelsetFont:[UIFontsystemFontOfSize:12]];

    [selfaddSubview:_yearLabel];

    

    //添加图片视图

    _imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(5,CGRectGetMaxY(_dayLabel.frame)+5,75,75)];

    [selfaddSubview:_imageView];

    

    //添加标题视图

    _titleLabel = [[UILabelalloc]initWithFrame:CGRectMake(CGRectGetMaxX(_imageView.frame)+5,CGRectGetMinY(_imageView.frame), [UIUtilsgetWindowWidth]-(CGRectGetMaxX(_imageView.frame)+5)-5,20)];

    [_titleLabelsetFont:[UIFontsystemFontOfSize:17]];

    [selfaddSubview:_titleLabel];

    

    //浏览次数标签

    _viewCountLabel = [[UILabelalloc]initWithFrame:CGRectMake(CGRectGetMaxX(_imageView.frame)+5,CGRectGetMaxY(_imageView.frame)-20, [UIUtils getWindowWidth]-(CGRectGetMaxX(_imageView.frame)+5),20)];

    [_viewCountLabelsetTextAlignment:NSTextAlignmentCenter];

    [_viewCountLabelsetTextColor:LIGHT_BLACK_COLOR];

    [_viewCountLabelsetFont:[UIFontsystemFontOfSize:13]];

    [selfaddSubview:_viewCountLabel];

}


//设置内容视图显示内容

-(void)setContentView:(WebInfo *)webInfo

{

    [_dayLabel setText:webInfo.dayString];

    [_monthLabelsetText:[NSStringstringWithFormat:@"%@",webInfo.monthString]];

    [_yearLabel setText:webInfo.yearString];

    [_titleLabelsetText:webInfo.title];

    [_viewCountLabelsetText:[NSStringstringWithFormat:@"浏览(%@)",webInfo.viewCount]];

    [_imageViewsd_setImageWithURL:[NSURLURLWithString:webInfo.imageUrl]placeholderImage:[UIImageimageNamed:@"lp_headPlaceHolder.png"]];

    

}


+(CGFloat)getCellHeight

{

   return120.0f;

}


@end


//

//  ShareView.m

//  我的旅拍1.0

//

//  Created by  on 15/7/17.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "ShareView.h"

#import "Header.h"

#import "UIUtils.h"


#define SHARE_CONTENT_HEIGHT 250


@interface ShareView ()

{

   UIView *_contentView;

}

@end


@implementation ShareView


-(id)initWithFrame:(CGRect)frame

{

   self = [superinitWithFrame:frame];

   if (self) {

        

        [selfaddContentView];

    }

    return self;

}


-(void)addContentView

{

    self.backgroundColor = [UIColorclearColor];

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(removeView)];

    [selfaddGestureRecognizer:tapGesture];

    

   _contentView = [[UIViewalloc]initWithFrame:CGRectMake(0, [UIUtilsgetWindowHeight], [UIUtilsgetWindowWidth],SHARE_CONTENT_HEIGHT)];

    UITapGestureRecognizer *tapContentGestrue = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:nil];

    [_contentViewaddGestureRecognizer:tapContentGestrue];

    

    [_contentViewsetBackgroundColor:SHARE_CONTENT_WHITE_COLOR];

    [selfaddSubview:_contentView];

    

    //添加contentView底部视图

   UIImage *contentFootImage = [UIImageimageNamed:@"ShareMenuFooter_light.png"];

   UIImageView *contentFootView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,_contentView.frame.size.height-contentFootImage.size.height,_contentView.frame.size.width, contentFootImage.size.height)];

    [contentFootView setUserInteractionEnabled:YES];

    [contentFootViewsetImage:contentFootImage];

    [_contentViewaddSubview:contentFootView];

    

    //添加取消按钮

    UIImage *cancelButtonNormal = [UIImageimageNamed:@"ShareMenuCancel_light_normal.png"];

    UIImage *cancelButtonHighlight = [UIImageimageNamed:@"ShareMenuCancel_light_selected.png"];

    UIButton *cancelButton = [UIButtonbuttonWithType:UIButtonTypeCustom];

    [cancelButton setTitleColor:[UIColorblackColor]forState:UIControlStateNormal];

    [cancelButton setTitle:@"取消"forState:UIControlStateNormal];

    [cancelButtonsetFrame:CGRectMake(10,10, contentFootView.frame.size.width-10-10, contentFootView.frame.size.height-10-10)];

    [cancelButton setBackgroundImage:[cancelButtonNormalstretchableImageWithLeftCapWidth:10topCapHeight:0]forState:UIControlStateNormal];

    [cancelButton setBackgroundImage:[cancelButtonHighlightstretchableImageWithLeftCapWidth:10topCapHeight:0]forState:UIControlStateHighlighted];

    [cancelButton addTarget:selfaction:@selector(removeView)forControlEvents:UIControlEventTouchUpInside];

    [contentFootViewaddSubview:cancelButton];

    

    [selfaddShareButtons];

}


//初始化分享按钮

- (void)addShareButtons

{

    NSArray *platforms =@[SOCIAL_SHARE_PLATFORM_WEIXIN,

                           SOCIAL_SHARE_PLATFORM_WEIXIN_TIMELINE,

                          SOCIAL_SHARE_PLATFORM_QQ,

                           SOCIAL_SHARE_PLATFORM_QQ_ZONE,

                           SOCIAL_SHARE_PLATFORM_SINAWEIBO,

                          SOCIAL_SHARE_PLATFORM_EMAIL,

                          SOCIAL_SHARE_PLATFORM_SMS,

                          SOCIAL_SHARE_PLATFORM_COPY];

    

   for (int i=0; i<platforms.count; i++) {

        //初始化透明的背景视图backView用来确定分享按钮的中心点坐标

       UIView *backView = [[UIViewalloc]initWithFrame:CGRectMake(10+i%4*([UIUtilsgetWindowWidth]-10*2)/4,10+i/4*80, ([UIUtilsgetWindowWidth]-10*2)/4,80)];

//        [backView setBackgroundColor:[UIColor yellowColor]];

//        backView.layer.borderColor = [UIColor redColor].CGColor;

//        backView.layer.borderWidth = 1.0f;

        [_contentViewaddSubview:backView];

        

       NSString *platform = platforms[i];

       //添加按钮

       UIButton *button = [selfgetShareButtonWithPlatform:platform];

        button.center = backView.center;

        [_contentViewaddSubview:button];

        //添加label

       UILabel *label = [selfgetSharelabelWithPlatform:platform];

       CGPoint labelCenter =CGPointMake(backView.center.x, backView.center.y+30);

        label.center = labelCenter;

        [_contentViewaddSubview:label];

    }

}


//获取对应平台的分享标签

-(UILabel *)getSharelabelWithPlatform:(NSString *)platform

{

   UILabel *buttonLabel = [[UILabelalloc]initWithFrame:CGRectMake(0,0,80, 20)];

    [buttonLabel setBackgroundColor:[UIColorclearColor]];

    [buttonLabel setTextAlignment:NSTextAlignmentCenter];

    [buttonLabelsetFont:[UIFontsystemFontOfSize:12]];

    if ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_SINAWEIBO]) {

        [buttonLabelsetText:@"新浪微博"];

    } elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_WEIXIN]) {

        [buttonLabelsetText:@"微信好友"];

    } elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_WEIXIN_TIMELINE]) {

        [buttonLabelsetText:@"朋友圈"];

    }elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_QQ]) {

        [buttonLabelsetText:@"QQ"];

    } elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_QQ_ZONE]) {

        [buttonLabelsetText:@"QQ空间"];

    } elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_EMAIL]) {

        [buttonLabelsetText:@"邮件"];

    } elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_SMS]) {

        [buttonLabelsetText:@"短信"];

    } elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_COPY]) {

        [buttonLabelsetText:@"复制链接"];

    }

   return buttonLabel;

}


//获取对应平台的分享按钮

-(UIButton *)getShareButtonWithPlatform:(NSString *)platform

{

    //获取相应图片

   UIImage *shareButtonImage;

    if ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_SINAWEIBO]) {

        shareButtonImage = [UIImageimageNamed:@"SocialSharePlatformIcon_sinaweibo.png"];

    } elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_WEIXIN]) {

        shareButtonImage = [UIImageimageNamed:@"SocialSharePlatformIcon_weixin.png"];

    } elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_WEIXIN_TIMELINE]) {

        shareButtonImage = [UIImageimageNamed:@"SocialSharePlatformIcon_weixinTimeline.png"];

    }elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_QQ]) {

        shareButtonImage = [UIImageimageNamed:@"SocialSharePlatformIcon_qqfriend.png"];

    } elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_QQ_ZONE]) {

        shareButtonImage = [UIImageimageNamed:@"SocialSharePlatformIcon_qzone.png"];

    } elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_EMAIL]) {

        shareButtonImage = [UIImageimageNamed:@"SocialSharePlatformIcon_email.png"];

    } elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_SMS]) {

        shareButtonImage = [UIImageimageNamed:@"SocialSharePlatformIcon_sms.png"];

    } elseif ([platformisEqualToString:SOCIAL_SHARE_PLATFORM_COPY]) {

        shareButtonImage = [UIImageimageNamed:@"SocialSharePlatformIcon_copy.png"];

    }

    //初始化按钮

    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];

    [button setTitle:platformforState:UIControlStateNormal];

    [button.titleLabelsetAlpha:0.0f];

    [button addTarget:selfaction:@selector(shareButtonPress:)forControlEvents:UIControlEventTouchUpInside];

    

    [buttonsetFrame:CGRectMake(0,0, shareButtonImage.size.width, shareButtonImage.size.height)];

//    [button setBackgroundColor:[UIColor redColor]];

    [button setBackgroundImage:shareButtonImageforState:UIControlStateNormal];

   return button;

}


-(void)shareButtonPress:(UIButton *)button

{

   if (self.delegate && [self.delegaterespondsToSelector:@selector(shareViewButtonPressed:)]) {

        [self.delegateshareViewButtonPressed:button.currentTitle];

    }

}


-(void)showInView:(UIView *)view

{

    [viewaddSubview:self];

    [UIViewanimateWithDuration:0.3

                    animations:^{

                         

                         [selfsetBackgroundColor:LIGHT_OPAQUE_BLACK_COLOR];

                         

                         [_contentViewsetFrame:CGRectMake(0, [UIUtilsgetWindowHeight]-SHARE_CONTENT_HEIGHT, [UIUtilsgetWindowWidth],SHARE_CONTENT_HEIGHT)];

                     }completion:nil];

}


-(void)removeView

{

    [UIViewanimateWithDuration:0.3

                    animations:^{

                         [selfsetBackgroundColor:[UIColorclearColor]];

                         [_contentViewsetFrame:CGRectMake(0, [UIUtilsgetWindowHeight], [UIUtilsgetWindowWidth],SHARE_CONTENT_HEIGHT)];

                     }

                    completion:^(BOOL finished) {

                         [selfremoveFromSuperview];

                     }];

}


@end





//

//  SetCell.m

//  我的旅拍1.0

//

//  Created by  on 15/7/27.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "SetCell.h"

#import "UIUtils.h"


#define Cell_Height 60


@interface SetCell ()

{

   UILabel *_label;

}

@end



@implementation SetCell


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

   self = [superinitWithStyle:stylereuseIdentifier:reuseIdentifier];

   if (self) {

        [selfaddContentView];

    }

    return self;

}


//添加内容视图

- (void)addContentView

{

    _label = [[UILabelalloc]initWithFrame:CGRectMake(15,0,200,Cell_Height)];

    [_labelsetFont:[UIFontboldSystemFontOfSize:20]];

    [selfaddSubview:_label];

}


- (void)setContentView:(NSString *)title

{

    [_labelsetText:title];

}


//获取cell的高度

+ (CGFloat)getCellHeight

{

   return Cell_Height;

}


@end




//

//  SetViewController.m

//  我的旅拍1.0

//

//  Created by  on 15/7/7.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "SetViewController.h"

#import "SetCell.h"

#import "HelpViewController.h"

#import "UIUtils.h"

#import "Header.h"



@interface SetViewController ()<UITableViewDataSource, UITableViewDelegate>

{

    UITableView *_tableView;

    NSArray *_setTitleArray;

    UISwitch *_switchPhotoButton;

}

@end


@implementation SetViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

   self.title =@"个人设置";

    [self.view setBackgroundColor:[UIColor whiteColor]];

    

    _setTitleArray =@[@"照片同步",@"使用助手",@"感谢好评"];

    

    //设置navigationbar

    [self setNavigationBar];

    

    //添加_tableView

    [self addTableView];

}


//添加_tableView

- (void)addTableView

{

    _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];

    _tableView.bounces =NO;

    _tableView.delegate =self;

    _tableView.dataSource =self;

    [self.view addSubview:_tableView];

}


//设置navigationbar

- (void)setNavigationBar

{

    //设置navigationbartitle颜色

    NSDictionary *dictionary =@{NSForegroundColorAttributeName:[UIColor whiteColor]};

    [self.navigationController.navigationBar setTitleTextAttributes:dictionary];

    

    //设置navigationBar背景图片

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"lp_nav_purple.png"] forBarMetrics:UIBarMetricsDefault];

    

    //添加返回按钮

    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"lp_nav_goback.png"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];

   self.navigationItem.leftBarButtonItem = leftBarButton;

    

    //设置navigationbar上的按钮颜色

    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

}


//返回

- (void)back

{

    [self dismissViewControllerAnimated:YES completion:nil];

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


#pragma mark UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

   return3;

}


- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

   staticNSString *cellIdentifier =@"cellIdentifier";

   SetCell *cell = [tableViewdequeueReusableCellWithIdentifier:cellIdentifier];

   if (!cell) {

        cell = [[SetCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:cellIdentifier];

        

    }

    

   if (indexPath.row ==0) {

        cell.selectionStyle =UITableViewCellSelectionStyleNone;

       _switchPhotoButton = [[UISwitchalloc]initWithFrame:CGRectMake([UIUtilsgetWindowWidth]-70-20,14,30, 20)];

        [_switchPhotoButtonsetOn:![USER_DEFAULTboolForKey:@"CancelPhotoOn"]];

        [_switchPhotoButtonaddTarget:selfaction:@selector(swichPhotoAction:)forControlEvents:UIControlEventValueChanged];

        _switchPhotoButton.onTintColor = [UIColorcolorWithPatternImage:[UIImageimageNamed:@"lp_nav_purple.png"]];

        [cell addSubview:_switchPhotoButton];

    }elseif (indexPath.row ==1){

        cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;

    }

    

   NSString *setTitle =_setTitleArray[indexPath.row];

    [cellsetContentView:setTitle];

   return cell;

}


//设置图片是否同步到本地相册的方法

- (void)swichPhotoAction:(id)sender

{

    UISwitch *switchButton = (UISwitch *)sender;

   if (switchButton.on) {

        NSLog(@"照片同步选择打开");

        [USER_DEFAULT setBool:NO forKey:@"CancelPhotoOn"];

    }else {

        NSLog(@"照片同步选择关闭");

        [USER_DEFAULT setBool:YES forKey:@"CancelPhotoOn"];

    }

    [USER_DEFAULT synchronize];

}


#pragma mark UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

   return [SetCell getCellHeight];

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

   if (indexPath.row ==1) {

        HelpViewController *helpViewController = [[HelpViewController alloc] init];

        [self.navigationController pushViewController:helpViewController animated:YES];

    }elseif (indexPath.row ==2) {

        //跳转到评论页面

        [[UIApplication sharedApplication]

         openURL:[NSURL

                  URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@", APPID]]];

    }

}


@end




//

//  HelpViewController.m

//  我的旅拍1.0

//

//  Created by  on 15/7/27.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "HelpViewController.h"


@interface HelpViewController ()

{

   UIWebView *_webView;

}

@end


@implementation HelpViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view.

   self.title =@"使用助手";

    

    //设置navigationbar

    [selfsetNavigationBar];

    

    //添加_webView

    [selfaddWebView];

}


//添加_webView

- (void)addWebView

{

    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"help" ofType:@"html"];

    NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

    

    CGRect frame =self.view.frame;

    frame.size.height = frame.size.height-44-20;

    _webView = [[UIWebView alloc] initWithFrame:frame];

    [_webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];

    [self.view addSubview:_webView];

}


//设置navigationbar

- (void)setNavigationBar

{

    //设置navigationbartitle颜色

    NSDictionary *dictionary =@{NSForegroundColorAttributeName:[UIColor whiteColor]};

    [self.navigationController.navigationBar setTitleTextAttributes:dictionary];

    //添加返回按钮

    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"lp_nav_goback.png"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];

   self.navigationItem.leftBarButtonItem = leftBarButton;

    

    //设置navigationbar上的按钮颜色

    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

}


//返回

- (void)back

{

    [self.navigationController popViewControllerAnimated:YES];

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end




//

//  MylistViewController.m

//  我的旅拍1.0

//

//  Created by  on 15/7/7.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "MylistViewController.h"

#import "Header.h"

#import "AFNetworking.h"

#import "WebInfo.h"

#import "MyListCell.h"

#import "WebViewController.h"


@interface MylistViewController ()<UITableViewDataSource,UITableViewDelegate>

{

   UITableView *_tableView;

   NSMutableArray *_webInfoArray;

}

@end


@implementation MylistViewController


- (void)viewDidLoad {

    [superviewDidLoad];

   self.title =@"我的旅拍";

    [self.viewsetBackgroundColor:[UIColorwhiteColor]];

    [selfsetNavigationBar];

    //添加TableView

    [selfaddTableView];

    //加载数据

    [selfloadData];

}


//添加TableView

-(void)addTableView

{

   CGRect frame =self.view.frame;

    frame.size.height = frame.size.height-44-20;

    _tableView = [[UITableViewalloc]initWithFrame:framestyle:UITableViewStylePlain];

    _tableView.dataSource =self;

    _tableView.delegate =self;

    [self.viewaddSubview:_tableView];

}


//加载数据

-(void)loadData

{

    if (!_webInfoArray) {

       _webInfoArray = [[NSMutableArrayalloc]init];

    }

    

    NSString *urlString = [NSStringstringWithFormat:@"%@%@",LocalWebSite,Request_Mylist];

   NSString *userId = [USER_DEFAULTobjectForKey:@"UserId"];

    

    NSDictionary *dictionary =@{@"userId":userId,@"lastdatetime":@"000000"};

    //初始化一个请求(同时也创建了一个线程)

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];

    //设置请求可以接受的内容的样式

    manager.responseSerializer.acceptableContentTypes = [NSSetsetWithObject:@"text/html"];

    //发送POST请求

    [managerPOST:urlStringparameters:dictionarysuccess:^(AFHTTPRequestOperation *operation,id responseObject) {

       NSLog(@"%@",responseObject);

       for (NSDictionary *dictionaryin responseObject) {

           WebInfo *webInfo = [[WebInfoalloc]initWithDictionary:dictionary];

            [_webInfoArrayaddObject:webInfo];

        }

        [_tableViewreloadData];

    }failure:^(AFHTTPRequestOperation *operation,NSError *error) {

       NSLog(@"%@",error);

    }];

    

}


-(void)setNavigationBar

{

    //设置navigationControllertitle颜色

    NSDictionary *dictionary =@{NSForegroundColorAttributeName:[UIColorwhiteColor]};

    [self.navigationController.navigationBarsetTitleTextAttributes:dictionary];

    //设置navigationBar的背景图片

    [self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"lp_nav_purple.png"]forBarMetrics:UIBarMetricsDefault];

    //添加返回按钮

    UIBarButtonItem *leftBarButton = [[UIBarButtonItemalloc]initWithImage:[UIImageimageNamed:@"lp_nav_goback.png"]style:UIBarButtonItemStylePlaintarget:selfaction:@selector(back)];

    

    self.navigationItem.leftBarButtonItem = leftBarButton;

    //设置navigationBar的按钮颜色

    [self.navigationController.navigationBarsetTintColor:[UIColorwhiteColor]];

    

}


-(void)back

{

    [selfdismissViewControllerAnimated:YEScompletion:nil];

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/********************UITableViewDataSource代理方法**********************/

#pragma mark UITableViewDataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return_webInfoArray.count;

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

   staticNSString *cellIdentifier =@"cellIdentifier";

   MyListCell *cell = [tableViewdequeueReusableCellWithIdentifier:cellIdentifier];

   if (!cell) {

        cell = [[MyListCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier];

    }

   WebInfo *webInfo =_webInfoArray[indexPath.row];

    [cellsetContentView:webInfo];

   return cell;

}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return [MyListCellgetCellHeight];

}


#pragma mark UITableViewDelegate

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

   WebInfo *webInfo =_webInfoArray[indexPath.row];

   WebViewController *webViewController = [[WebViewControlleralloc]initWithWebInfo:webInfowebViewType:WEBVIEW_TYPE_LIST];

    [self.navigationControllerpushViewController:webViewControlleranimated:YES];

}


@end





//

//  LocalDraftViewController.m

//  我的旅拍1.0

//

//  Created by on 15/7/7.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "LocalDraftViewController.h"

#import "FMDBTool.h"

#import "FMDB.h"

#import "DraftInfo.h"

#import "UIUtils.h"

#import "DraftViewController.h"

#import "Header.h"


#define Table_Name @"draft_table"


@interface LocalDraftViewController ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate,DraftVCDelegate>

{

   UITableView *_tableView;

   FMDatabase *_db;

   NSMutableArray *_draftInfoArray;

   NSIndexPath *_deleteIndexPath;

}

@end


@implementation LocalDraftViewController


- (void)viewDidLoad {

    [superviewDidLoad];

   self.title =@"本地草稿";

    [self.navigationController.viewsetBackgroundColor:LIGHT_PURPLE_COLOR];

    [self.viewsetBackgroundColor:[UIColorwhiteColor]];

    [selfsetNavigationBar];

    

    //添加tableView

    [selfaddTableViw];

    //加载数据

    [selfloadData];


}


-(void)viewWillAppear:(BOOL)animated

{

    [superviewWillAppear:animated];

    

    [_tableView reloadData];

    

    self.navigationController.navigationBarHidden =NO;

}


//添加tableView

-(void)addTableViw

{

    _tableView = [[UITableViewalloc]initWithFrame:self.view.framestyle:UITableViewStylePlain];

    _tableView.separatorColor = [UIColororangeColor];

    _tableView.dataSource =self;

    _tableView.delegate =self;

    [self.viewaddSubview:_tableView];

}


-(void)setNavigationBar

{

    //设置navigationControllertitle颜色

    NSDictionary *dictionary =@{NSForegroundColorAttributeName:[UIColorwhiteColor]};

    [self.navigationController.navigationBarsetTitleTextAttributes:dictionary];

    //设置navigationBar的背景图片

    [self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"lp_nav_purple.png"]forBarMetrics:UIBarMetricsDefault];

    //添加返回按钮

    UIBarButtonItem *leftBarButton = [[UIBarButtonItemalloc]initWithImage:[UIImageimageNamed:@"lp_nav_goback.png"]style:UIBarButtonItemStylePlaintarget:selfaction:@selector(back)];

    

    self.navigationItem.leftBarButtonItem = leftBarButton;

    //设置navigationBar的按钮颜色

    [self.navigationController.navigationBarsetTintColor:[UIColorwhiteColor]];

    

}

/*****************************数据库的运用***************************/

//加载数据

-(void)loadData

{

    if (!_draftInfoArray) {

       _draftInfoArray = [[NSMutableArrayalloc]init];

    }

    

   if (!_db) {

       _db = [FMDBToolcreateDataBase];

    }

   if ([_dbopen]) {


       NSArray *array = [FMDBToolqueryOnDB:_dbwithTableName:Table_Name];

        [_draftInfoArrayaddObjectsFromArray:array];

        [_tableViewreloadData];

    }

    

}


//删除草稿

-(void)deleteDraft:(NSIndexPath *)indexPath

{

    //获取相应的draftId

   DraftInfo *draftInfo =_draftInfoArray[indexPath.row];

   int draftId = draftInfo.draftId;

    

    //删除数据库中的一条数据

   if ([_dbopen]) {

       BOOL result = [FMDBTooldeleteOnDB:_dbwithTableName:Table_NameandDraftId:draftId];

       if (result) {

           NSLog(@"删除成功");

        }else{

           NSLog(@"删除失败");

        }

        [_dbclose];

    }

    

    //删除草稿对应的图片文件夹

    NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

   NSString *documentPath = [pathslastObject];

   NSString *draftPath = [documentPathstringByAppendingPathComponent:[NSStringstringWithFormat:@"Draft/draft%d",draftId]];

    if ([NSFileManagerdefaultManager]) {

        [[NSFileManagerdefaultManager]removeItemAtPath:draftPatherror:nil];

    }

    

    //删除_draftInfoArray中的DraftInfo对象

    [_draftInfoArrayremoveObjectAtIndex:indexPath.row];

    

    //删除_tableView中的一行

    [_tableViewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationNone];

    

}


//返回

-(void)back

{

    [selfdismissViewControllerAnimated:YEScompletion:nil];

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*******************UITableViewDataSource的代理方法**********************/

#pragma mark UITableViewDataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return_draftInfoArray.count;

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

   staticNSString *cellIndentifier =@"cellIndentifier";

   UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:cellIndentifier];

   if (!cell) {

        cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:cellIndentifier];

    }

   DraftInfo *draftInfo =_draftInfoArray[indexPath.row];

   if ([UIUtilsisBlankString:draftInfo.title]) {

        [cell.textLabelsetText:@"无标题"];

    }

   else{

        [cell.textLabelsetText:draftInfo.title];

    }

    

    [cell.detailTextLabelsetText:draftInfo.dateLine];

    

   return cell;

}


/********************UITableViewDelegate代理方法***********************/

#pragma mark UITableViewDelegate

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

   _deleteIndexPath = indexPath;

   DraftInfo *draftInfo =_draftInfoArray[indexPath.row];

   DraftViewController *draftViewController = [[DraftViewControlleralloc]initWithDraftInfo:draftInfo];

    draftViewController.delegate =self;

    [self.navigationControllerpushViewController:draftViewControlleranimated:YES];

}


-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

   _deleteIndexPath = indexPath;

    UIAlertView *alert = [[UIAlertViewalloc]

                         initWithTitle:@"是否要删除草稿"

                         message:nil

                         delegate:self

                         cancelButtonTitle:@"取消"

                         otherButtonTitles:@"确定",nil];

    [alertshow];

}


/*******************UIAlertViewDelegate代理方法************************/

#pragma mark UIAlertViewDelegate

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

   if (buttonIndex ==1) {

       //删除草稿

        [selfdeleteDraft:_deleteIndexPath];

    }elseif (buttonIndex ==0){

       _tableView.editing =NO;

    }

}


/******************DraftVCDelegate的代理方法*********************/

#pragma mark DraftVCDelegate

-(void)draftVCDeleteDraft

{

    [selfdeleteDraft:_deleteIndexPath];

}


@end






//

//  DraftViewController.m

//  我的旅拍1.0

//

//  Created by  on 15/7/16.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "DraftViewController.h"

#import "EditView.h"

#import "DraftInfo.h"

#import "ImageInfo.h"

#import "UIUtils.h"

#import "AFNetworking.h"

#import "PostProgressView.h"

#import "WebViewController.h"

#import "WebInfo.h"

#import "FMDB.h"

#import "FMDBTool.h"


#define Table_Name @"draft_table"


@interface DraftViewController ()<EditViewDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,UIAlertViewDelegate>

{

   EditView *_editView;

   DraftInfo *_draftInfo;

   NSMutableArray *_imageInfoArray;

   UpdateType _updateType;//更新类型

   int _editIndex;//被编辑的索引

   PostProgressView *_postProgressView;//上传进度

   FMDatabase *_db;//数据库

   BOOL _isEdit;//判断是否修改了草稿

}

@end


@implementation DraftViewController


-(id)initWithDraftInfo:(DraftInfo *)draftInfo

{

   self = [superinit];

   if (self) {

       _draftInfo = draftInfo;

    }

    return self;

}


- (void)viewDidLoad {

    [superviewDidLoad];

    //隐藏navigationBar

    self.navigationController.navigationBarHidden =YES;

   

    //添加编辑视图

    [selfaddEditView];

    //加载数据

    [selfloadData];

}


//添加编辑视图

-(void)addEditView

{

    _editView = [[EditViewalloc]initWithFrame:self.view.frame];

    _editView.delegate =self;

    [self.viewaddSubview:_editView];

}


//加载数据

-(void)loadData

{

    if (!_imageInfoArray) {

       _imageInfoArray = [[NSMutableArrayalloc]init];

    }

    

   for (int i=0; i<_draftInfo.imageCount; i++) {

       NSString *text =_draftInfo.textArray[i];

        UIImage *imaeg = [selfgetImageWithDraftId:_draftInfo.draftIdandImageId:i];

       ImageInfo *imageInfo = [[ImageInfoalloc]initWithImage:imaegandText:text];

        

        [_imageInfoArrayaddObject:imageInfo];

    }

    

    _editView.titleView.text =_draftInfo.title;

    //刷新_editView

    [_editViewreloadEditViewWithArray:_imageInfoArrayandUpdateType:UPDATETYPE_FOR_ADD_MORE_OBJECTS];

    

}


//获取图片

-(UIImage *)getImageWithDraftId:(int)draftId andImageId:(int)imageId

{

    NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

   NSString *documentPath = [pathslastObject];

   NSString *draftPath = [documentPathstringByAppendingPathComponent:[NSStringstringWithFormat:@"Draft/draft%d",draftId]];

    NSString *imagePath = [draftPathstringByAppendingPathComponent:[NSStringstringWithFormat:@"image %d.jpg",imageId]];

   UIImage *image = [UIImageimageWithContentsOfFile:imagePath];

   return image;

}


//上传多张图片

-(void)uploadImages

{

    if ([UIUtilsisBlankString:_editView.titleView.text]) {

        [_editViewtapTitleView];

    }else{

        

        [selfshowPostProgressView];

        

        //AFNetworking发送图片到服务器

       NSString *urlString = [NSStringstringWithFormat:@"%@%@",LocalWebSite,Request_Upload];

        

       //参数字典

       NSString *uploadTimeString = [selfgetCurrentDateString];

       NSString *pageCountString = [NSStringstringWithFormat:@"%d",(int)_imageInfoArray.count];

       NSString *userIDString = [USER_DEFAULTobjectForKey:@"UserId"];

       NSString *titleString =_editView.titleView.text;

       NSDictionary *parameters = [NSDictionarydictionaryWithObjectsAndKeys:@"ios",@"platform",uploadTimeString,@"uploadTime",pageCountString,@"pageCount",userIDString,@"userId",titleString,@"title",nil];

        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];

        //设置请求可以接受的内容的样式

        manager.responseSerializer.acceptableContentTypes = [NSSetsetWithObject:@"text/html"];

       AFHTTPRequestOperation *uploadOperation = [managerPOST:urlStringparameters: parametersconstructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

            

           for (int i=0; i<_imageInfoArray.count; i++) {

               ImageInfo *imageInfo =_imageInfoArray[i];

               UIImage *image = imageInfo.image;

               NSData *imageData =UIImageJPEGRepresentation(image, 1.0);

               //添加图片

                [formDataappendPartWithFileData:imageDataname:[NSStringstringWithFormat:@"image%d",i+1]fileName:@"image"mimeType:@"image/jpg"];

               if (![UIUtilsisBlankString:imageInfo.text]) {

                   //添加文字

                    [formDataappendPartWithFormData:[imageInfo.textdataUsingEncoding:NSUTF8StringEncoding]name:[NSStringstringWithFormat:@"text%d",i+1]];

                }

            }

        }success:^(AFHTTPRequestOperation *operation,id responseObject) {

            //NSLog(@"成功 %@",responseObject);

            //移除_postProgressView

            [_postProgressViewremoveView];

            

           WebInfo *webInfo = [[WebInfoalloc]initWithDictionary:responseObject];

           WebViewController *webViewController = [[WebViewControlleralloc]initWithWebInfo:webInfowebViewType:WEBVIEW_TYPE_POST];

           UINavigationController *navigationController =[[UINavigationControlleralloc]initWithRootViewController:webViewController];

            [selfpresentViewController:navigationControlleranimated:YEScompletion:nil];

        }failure:^(AFHTTPRequestOperation *operation,NSError *error) {

           NSLog(@"失败 %@",error);

            //移除_postProgressView

            [_postProgressViewremoveView];

        }];

        //添加上传进度block

        [uploadOperationsetUploadProgressBlock:^(NSUInteger bytesWritten,longlong totalBytesWritten,longlong totalBytesExpectedToWrite) {

            //_postProgressView更新进度

            [_postProgressViewupdateWithValue:(double)totalBytesWritten/totalBytesExpectedToWrite];

        }];

        

    }

}


//展示进度视图

-(void)showPostProgressView

{

    if (!_postProgressView) {

       _postProgressView = [[PostProgressViewalloc]initWithFrame:self.view.frame];

    }

    [_postProgressViewshowInView:self.view];

}


//获得当前的时间戳

- (NSString *)getCurrentDateString

{

    NSTimeZone *zone = [NSTimeZonesystemTimeZone];

   NSTimeInterval delta = [zonesecondsFromGMTForDate:[NSDatedate]];

    NSString *string = [NSStringstringWithFormat:@"%f",[[NSDatedate]timeIntervalSince1970] + delta];

    NSString *dateString = [[stringcomponentsSeparatedByString:@"."]objectAtIndex:0];

   return dateString;

}



//更新

-(void)updateImageInfo:(ImageInfo *)imageInfo updateType:(UpdateType)updateType index:(int)index

{

    //草稿被修改

   _isEdit =YES;

    if (updateType ==UPDATETYPE_FOR_ADD_ONE_OBJECT) {

        [_imageInfoArrayaddObject:imageInfo];

    }elseif (updateType ==UPDATETYPE_FOR_EDIT_ONE_OBJECT){

        [_imageInfoArrayreplaceObjectAtIndex:indexwithObject:imageInfo];

    }elseif (updateType ==UPDATETYPE_FOR_DELETE_ONE_OBJECT){

        

       if (_imageInfoArray.count ==1) {

           UIAlertView *alertView = [[UIAlertViewalloc]

                                     initWithTitle:@"是否要删除草稿"

                                     message:nil

                                     delegate:self

                                     cancelButtonTitle:@"取消"

                                     otherButtonTitles:@"确定",nil];

            alertView.tag =2;

            [alertViewshow];

        }else{

            [_imageInfoArrayremoveObjectAtIndex:index];

        }

        

    }

    

    

    //刷新_editViewtableView中显示的内容

    [_editViewreloadEditViewWithArray:_imageInfoArrayandUpdateType:updateType];

}


//拍照按钮被点击

-(void)cameraButtonPressed

{

    

    if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIImagePickerController *imagePicker = [[UIImagePickerControlleralloc]init];

        imagePicker.delegate =self;

        imagePicker.sourceType =UIImagePickerControllerSourceTypeCamera;

        [selfpresentViewController:imagePickeranimated:YEScompletion:nil];

    }else{

       UIAlertView *alertView = [[UIAlertViewalloc]

                                 initWithTitle:@"您手机没有拍照功能"

                                 message:nil

                                 delegate:nil

                                 cancelButtonTitle:@"知道了"

                                 otherButtonTitles:nil];

        [alertViewshow];

    }

    

}


//相册按钮被点击

-(void)libraryButtonpressed

{

    

    if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

        UIImagePickerController *imagePicker = [[UIImagePickerControlleralloc]init];

        imagePicker.delegate =self;

        imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;

        [selfpresentViewController:imagePickeranimated:YEScompletion:nil];

    }else{

       UIAlertView *alertView = [[UIAlertViewalloc]

                                 initWithTitle:@"您手机没有相册功能"

                                 message:nil

                                 delegate:nil

                                 cancelButtonTitle:@"知道了"

                                 otherButtonTitles:nil];

        [alertViewshow];

    }

    

}


//把状态栏设置为白色

-(void)setStatusBarColor

{

    //设置状态栏为白色

    [[UIApplicationsharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];

}


//保存草稿

-(void)saveDraft

{

    //图片描述数组的字符串

    NSMutableArray *textArray = [[NSMutableArrayalloc]init];

   for (ImageInfo *imageInfoin_imageInfoArray) {

       if ([UIUtilsisBlankString:imageInfo.text]) {

            [textArrayaddObject:@""];

        }else{

            [textArrayaddObject:imageInfo.text];

        }

    }

   NSError *error =nil;

    NSData *textData = [NSJSONSerializationdataWithJSONObject:textArrayoptions:NSJSONWritingPrettyPrintederror:&error];

    NSString *textString = [[NSStringalloc]initWithData:textDataencoding:NSUTF8StringEncoding];

    

    //标题字符串

   NSString *titleString =_editView.titleView.text;

    //图片个数

   int imageCount = (int)_imageInfoArray.count;

    //草稿id

   int draftId =_draftInfo.draftId;

    

    //更新数据库中的一条数据

   BOOL result = [FMDBToolupdateOnDB:_dbwithTableName:Table_NameandTitle:titleStringimageCount:imageCount textString:textStringdraftId:draftId];

   if (result) {

       NSLog(@"更新成功");

        

        //更新_draftInfo数据

       _draftInfo.title = titleString;

       _draftInfo.imageCount = imageCount;

       _draftInfo.textArray = textArray;

        

        //存储图片到磁盘

        [selfsaveImagesWithDraftId:draftId];

    }else{

       NSLog(@"更新失败");

    }

    [_dbclose];

}


//存储图片到磁盘

-(void)saveImagesWithDraftId:(int)draftId

{

    NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

   NSString *docPath = [pathslastObject];

    NSString *draftPath = [docPathstringByAppendingPathComponent:[NSStringstringWithFormat:@"Draft/draft%d",draftId]];

    //判断文件夹路径是否存在 如果不存在 创建文件夹

    if (![[NSFileManagerdefaultManager]fileExistsAtPath:draftPath]) {

        [[NSFileManagerdefaultManager]createDirectoryAtPath:draftPathwithIntermediateDirectories:YESattributes:nilerror:nil];

    }

   for (int i=0; i<_imageInfoArray.count; i++) {

       ImageInfo *imageInfo =_imageInfoArray[i];

       UIImage *image = imageInfo.image;

       NSData *data =UIImageJPEGRepresentation(image,1.0f);

        NSString *imagePath = [draftPathstringByAppendingPathComponent:[NSStringstringWithFormat:@"image %d.jpg",i]];

        [datawriteToFile:imagePathatomically:YES];

    }

}



- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/***************UIImagePickerControllerDelegate代理方法*****************/

#pragma mark UIImagePickerControllerDelegate

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

    //获取原始图片

    UIImage *originalImage = [infoobjectForKey:@"UIImagePickerControllerOriginalImage"];

   ImageInfo *imageInfo;

    if (_updateType ==UPDATETYPE_FOR_EDIT_ONE_OBJECT) {

       ImageInfo *beforeImageInfo =_imageInfoArray[_editIndex];

        imageInfo = [[ImageInfoalloc]initWithImage:originalImageandText:beforeImageInfo.text];

    }else{

        imageInfo = [[ImageInfoalloc]initWithImage:originalImageandText:nil];

    }

    

    //设置状态栏为白色

    [selfsetStatusBarColor];

    [selfdismissViewControllerAnimated:YEScompletion:^{

       //更新

        [selfupdateImageInfo:imageInfoupdateType:_updateTypeindex:_editIndex];

    }];

    

}


-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

{

    //设置状态栏为白色

    [selfsetStatusBarColor];

    [selfdismissViewControllerAnimated:YEScompletion:nil];

}



/******************EditViewDelegate的代理方法*******************/

#pragma mark EditViewDelegate

-(void)editViewBackButtonPressed

{

    //标题被修改则判断_isEdit = YES

    if (![_draftInfo.titleisEqualToString:_editView.titleView.text]) {

       _isEdit =YES;

    }

   if (_isEdit) {

       UIAlertView *alertView = [[UIAlertViewalloc]

                                 initWithTitle:@"是否保存本地草稿"

                                 message:@"保存本地草稿后可以再次编辑并且上传"

                                 delegate:self

                                 cancelButtonTitle:@"不保存"

                                 otherButtonTitles:@"保存",nil];

        alertView.tag =1;

        [alertViewshow];

    }else{

        [self.navigationControllerpopViewControllerAnimated:YES];

    }

       

}


-(void)editViewUploadButtonPressed

{

    //上传多张图片

    [selfuploadImages];

}


-(void)editViewCameraButtonPressed

{

    _updateType =UPDATETYPE_FOR_ADD_ONE_OBJECT;

    [selfcameraButtonPressed];

}


-(void)editViewLibraryButtonPressed

{

    _updateType =UPDATETYPE_FOR_ADD_ONE_OBJECT;

    [selflibraryButtonpressed];

}


-(void)editViewActionSheetCameraButtonPressed:(int)index

{

   _editIndex = index;

    _updateType =UPDATETYPE_FOR_EDIT_ONE_OBJECT;

    [selfcameraButtonPressed];

}


-(void)editViewActionSheetLibraryButtonPressed:(int)index

{

   _editIndex = index;

    _updateType =UPDATETYPE_FOR_EDIT_ONE_OBJECT;

    [selflibraryButtonpressed];

}


//删除一个ImageInfo对象

-(void)editViewDeleteImageInfoAtIndex:(int)index

{

    [selfupdateImageInfo:nilupdateType:UPDATETYPE_FOR_DELETE_ONE_OBJECTindex:index];

}


-(void)editViewInputTextViewSaveButtonPressedWithImageInfo:(ImageInfo *)imageInfo andIndex:(int)index

{

   NSLog(@"text %@ index %d",imageInfo.text,index);

    [selfupdateImageInfo:imageInfoupdateType:UPDATETYPE_FOR_EDIT_ONE_OBJECTindex:index];

}


/******************UIAlertViewDelegate的代理方法********************/

#pragma mark UIAlertViewDelegate

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

   if (alertView.tag ==1) {

       if (buttonIndex ==1) {

           if (!_db) {

               _db = [FMDBToolcreateDataBase];

            }

           if ([_dbopen]) {

               //保存更改的草稿

                [selfsaveDraft];

            }

        }

        [self.navigationControllerpopViewControllerAnimated:YES];

    }elseif (alertView.tag ==2){

       if (buttonIndex ==1) {

           NSLog(@"删除草稿");

            [self.navigationControllerpopViewControllerAnimated:YES];

           if (self.delegate && [self.delegaterespondsToSelector:@selector(draftVCDeleteDraft)]) {

                [self.delegatedraftVCDeleteDraft];

            }

            

        }else{

           NSLog(@"取消删除");

        }

    

    }

}




@end



//

//  WebViewController.m

//  我的旅拍1.0

//

//  Created by on 15/7/15.

//  Copyright (c) 2015 sdzy. All rights reserved.

//


#import "WebViewController.h"

#import "WebInfo.h"

#import "ShareView.h"

#import "UIUtils.h"

#import "Header.h"

#import <MessageUI/MessageUI.h>

#import "WeiXinViewController.h"

#import "QQViewController.h"




@interface WebViewController ()<ShareViewDelegate,MFMessageComposeViewControllerDelegate,MFMailComposeViewControllerDelegate,WeiXinVCDelegate>

{

    WebInfo *_webInfo;

    UIWebView *_webView;

    WebViewType _webViewType;

    ShareView *_shareView;

    

    WeiXinViewController *_weixinVC;

    QQViewController *_qqViewController;

}

@end


@implementation WebViewController


-(id)initWithWebInfo:(WebInfo *)webInfo webViewType:(WebViewType)webViewType

{

   self = [super init];

   if (self) {

        _webInfo = webInfo;

        _webViewType = webViewType;

    }

    return self;

}


- (void)viewDidLoad {

    [super viewDidLoad];

    //添加网页视图

    [self addWebView];

    //设置navigationbar

    [self setNavigationBar];

}


//添加网页视图

-(void)addWebView

{

    CGRect frame =self.view.frame;

    frame.size.height = frame.size.height-44-20;

    _webView = [[UIWebView alloc] initWithFrame:frame];

    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_webInfo.webUrl]]];

    [self.view addSubview:_webView];


}


-(void)setNavigationBar

{

    //设置navigationControllertitle颜色

    NSDictionary *dictionary =@{NSForegroundColorAttributeName:[UIColor whiteColor]};

    [self.navigationController.navigationBar setTitleTextAttributes:dictionary];

    //设置navigationBar的背景图片

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"lp_nav_purple.png"] forBarMetrics:UIBarMetricsDefault];

    //添加返回按钮

    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"lp_nav_goback.png"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];

    

    //添加分享按钮

    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"lp_nav_share.png"] style:UIBarButtonItemStylePlain target:self action:@selector(share)];

   self.navigationItem.rightBarButtonItem = rightBarButton;

    

   self.navigationItem.leftBarButtonItem = leftBarButton;

    //设置navigationBar的按钮颜色

    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

    

}


//返回

-(void)back

{

   if (_webViewType == WEBVIEW_TYPE_POST) {

        [self dismissViewControllerAnimated:YES completion:nil];

    }else{

        [self.navigationController popViewControllerAnimated:YES];

    }

    

}


//分享

-(void)share

{

   if (!_shareView) {

        _shareView = [[ShareView alloc] initWithFrame:CGRectMake(0,0, [UIUtils getWindowWidth], [UIUtils getWindowHeight])];

        _shareView.delegate =self;

    }

    [_shareView showInView:self.navigationController.view];

}


/******************各平台分享方法*********************/

#pragma mark 各平台分享方法

//分享微信

-(void)shareWeiXin:(int)scene

{

   if (!_weixinVC) {

        _weixinVC = [[WeiXinViewController alloc] init];

    }

    [_weixinVC sendWeiXinWithWebInfo:_webInfo andScene:scene];

}


//分享QQ

-(void)shareQQWithPlatform:(NSString *)platform

{

   if (!_qqViewController) {

        _qqViewController = [[QQViewController alloc] init];

        _qqViewController.delegate =self;

    }

    [_qqViewController sendQQWithWebInfo:_webInfo andScene:platform];

}



//分享邮件

-(void)shareEmail

{

   BOOL canSendEmail = [MFMailComposeViewController canSendMail];

   if (canSendEmail) {

        //创建邮件视图控制器

        MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];

        NSString *subjectString = [NSString stringWithFormat:@"[旅拍] %@",_webInfo.title];

        NSString *bodyString = [NSString stringWithFormat:@"我制作了一个名为\"%@\"的旅拍,赶快来欣赏吧!\n\n请猛戳链接:\n%@\n\n旅拍-最方便的拍照记录分享工具",_webInfo.title,_webInfo.webUrl];

        [mailComposeViewController setSubject:subjectString];

        [mailComposeViewController setMessageBody:bodyString isHTML:NO];

        [mailComposeViewController setMailComposeDelegate:self];

        [self presentViewController:mailComposeViewController animated:YES completion:nil];

    }else{

        NSLog(@"没有邮箱功能");

    }

}


//分享短信

-(void)shareMessage

{

    //判断是否可以发送短信

   BOOL canSendMessage = [MFMessageComposeViewController canSendText];

   if (canSendMessage) {

        //创建短信视图控制器

        MFMessageComposeViewController *messageComposeViewController = [[MFMessageComposeViewController alloc] init];

         NSString *bodyString = [NSString stringWithFormat:@"我制作了一个名为\"%@\"的旅拍,赶快来欣赏吧!\n\n请猛戳链接:\n%@\n\n旅拍-最方便的拍照记录分享工具",_webInfo.title,_webInfo.webUrl];

        [messageComposeViewController setBody:bodyString];

        messageComposeViewController.messageComposeDelegate =self;

        [self presentViewController:messageComposeViewController animated:YES completion:nil];

    }else{

        NSLog(@"没有发短信功能");

    }

}


//分享复制

-(void)shareCopy

{

    //剪贴板

    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];

    [pasteboard setString:_webInfo.webUrl];

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*******************ShareViewDelegate的代理方法**********************/

#pragma mark ShareViewDelegate

-(void)shareViewButtonPressed:(NSString *)platform

{

    NSLog(@"%@",platform);

   if ([platform isEqualToString:SOCIAL_SHARE_PLATFORM_SINAWEIBO]) {

        //分享到新浪微博

        

    }elseif ([platform isEqualToString:SOCIAL_SHARE_PLATFORM_WEIXIN]) {

       //分享微信

        [self shareWeiXin:WXSceneSession];

    }elseif ([platform isEqualToString:SOCIAL_SHARE_PLATFORM_WEIXIN_TIMELINE]) {

        //分享微信朋友圈

        [self shareWeiXin:WXSceneTimeline];

    }elseif ([platform isEqualToString:SOCIAL_SHARE_PLATFORM_QQ]){

       //分享到QQ

        [self shareQQWithPlatform:platform];

    }elseif ([platform isEqualToString:SOCIAL_SHARE_PLATFORM_QQ_ZONE]) {

        //分享到QQ空间

        [self shareQQWithPlatform:platform];

    }elseif ([platform isEqualToString:SOCIAL_SHARE_PLATFORM_EMAIL]) {

       //分享邮箱

        [self shareEmail];

    }elseif ([platform isEqualToString:SOCIAL_SHARE_PLATFORM_SMS]) {

       //分享短信

        [self shareMessage];

    }elseif ([platform isEqualToString:SOCIAL_SHARE_PLATFORM_COPY]) {

       //分享复制

        [self shareCopy];

    }

}


/***********MFMessageComposeViewControllerDelegate的代理方法**************/

#pragma mark MFMessageComposeViewControllerDelegate

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result

{

   switch (result) {

        caseMessageComposeResultCancelled:

           NSLog(@"取消发送短信");

           break;

        caseMessageComposeResultFailed:

           NSLog(@"发送短信失败");

           break;

        caseMessageComposeResultSent:

           NSLog(@"发送短信成功");

           break;

            

       default:

           break;

    }

    [selfdismissViewControllerAnimated:YEScompletion:nil];

    

}


#pragma mark MFMailComposeViewControllerDelegate

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error

{

   switch (result) {

        caseMFMailComposeResultCancelled:

           NSLog(@"取消发送邮件");

           break;

        caseMFMailComposeResultSent:

           NSLog(@"发送邮件成功");

           break;

       case MFMailComposeResultFailed:

            NSLog(@"发送邮件失败");

           break;

       case MFMailComposeResultSaved:

            NSLog(@"发送邮件保存");

           break;

            

       default:

           break;

    }

    [self dismissViewControllerAnimated:YES completion:nil];

}


/******************WeiXinVCDelegate的代理方法**********************/

#pragma mark WeiXinVCDelegate


@end



0 1
原创粉丝点击