FollowHeartViewController.m 8.96 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1
//
2
//  FollowHeartViewController.m
曹云霄's avatar
曹云霄 committed
3 4
//  Lighting
//
5
//  Created by 曹云霄 on 16/5/4.
曹云霄's avatar
曹云霄 committed
6 7 8
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

9
#import "FollowHeartViewController.h"
zhu's avatar
zhu committed
10 11
#import <QuartzCore/QuartzCore.h>
#import "ImageCropperView.h"
曹云霄's avatar
曹云霄 committed
12

13
@interface FollowHeartViewController ()
曹云霄's avatar
曹云霄 committed
14 15 16

@end

17
@implementation FollowHeartViewController
曹云霄's avatar
曹云霄 committed
18 19 20 21

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
zhu's avatar
zhu committed
22 23
    [self configSubView];
    
曹云霄's avatar
曹云霄 committed
24
}
zhu's avatar
zhu committed
25 26
-(void)configSubView
{
zhu's avatar
zhu committed
27
    self.productModelArray=[[NSMutableArray alloc]init];
zhu's avatar
zhu committed
28 29 30
    self.backGroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"backView.png"]];
    self.backGroundImageView.frame=CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [self.view addSubview:self.backGroundImageView];
zhu's avatar
zhu committed
31
    self.leftSubView=[[LeftSubView alloc]initWithFrame:CGRectMake(0, 0, 200, ScreenHeight-150)];
zhu's avatar
zhu committed
32 33
    self.leftSubView.delegate=self;
    [self.view addSubview:self.leftSubView];
zhu's avatar
zhu committed
34
    self.rightSubView=[[RightSubView alloc]initWithFrame:CGRectMake(ScreenWidth-200, 0, 200, ScreenHeight-150)];
zhu's avatar
zhu committed
35
    self.rightSubView.delegate=self;
zhu's avatar
zhu committed
36 37
    [self.view addSubview:self.rightSubView];
    
zhu's avatar
zhu committed
38
    self.footSubView=[[FootSubView alloc]initWithFrame:CGRectMake(0, ScreenHeight-150, ScreenWidth, 150)];
zhu's avatar
zhu committed
39
    self.footSubView.delegate=self;
zhu's avatar
zhu committed
40
    [self.view addSubview:self.footSubView];
zhu's avatar
zhu committed
41
   
zhu's avatar
zhu committed
42
}
zhu's avatar
zhu committed
43

zhu's avatar
zhu committed
44
#pragma  subView  delegate
zhu's avatar
zhu committed
45 46 47 48 49 50 51 52 53 54
- (void)buttonClick:(NSInteger)btnTag withButton:(UIButton *)button
{
    switch (btnTag) {
        case 100:  //返回
        {
            [self.view removeFromSuperview];
        }
            break;
        case 101:  //购物车
        {
zhu's avatar
zhu committed
55
             [self addShoppingView];
zhu's avatar
zhu committed
56 57 58 59
        }
            break;
        case 102:  //分享
        {
zhu's avatar
zhu committed
60
            [self addShareView:button];
zhu's avatar
zhu committed
61 62 63 64
        }
            break;
        case 103:  //自定义场景
        {
65
            [self addCameraView:button];
zhu's avatar
zhu committed
66 67 68 69 70 71 72 73 74 75 76 77
        }
            break;
        case 104:  //全屏
        {

            [self setViewAnimations:button];
            
        }
            break;
        case 105: //帮助
        {
            
zhu's avatar
zhu committed
78 79 80 81 82 83 84 85 86 87
        }
            break;
        case 200: //场景
        {
            [self addSceneLibraryView];
        }
            break;
        case 300: //产品
        {
            [self addProductLibraryView];
zhu's avatar
zhu committed
88 89 90 91 92 93 94
        }
            break;
            
        default:
            break;
    }

zhu's avatar
zhu committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108
}
-(void)addShareView:(UIButton *)sender
{
    ShareViewController *shareVC = [[ShareViewController alloc]init];
    shareVC.delegate = self;
    shareVC.preferredContentSize = CGSizeMake(280, 150);
    shareVC.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *pop = shareVC.popoverPresentationController;
//    箭头方向
    pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pop.sourceView = shareVC.view;
    pop.barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:sender];
    [self presentViewController:shareVC animated:YES completion:nil];

109 110 111 112 113 114 115 116 117 118 119 120
}
//添加自定义场景
-(void)addCameraView:(UIButton *)sender
{
    self.cameraView=[[CameraView alloc]init];
    self.cameraView.view.backgroundColor=[UIColor clearColor];
//    //    self.cameraView.delegate=self;
    [self.view addSubview:self.cameraView.view];
//     [SHARED_APPDELEGATE.window.rootViewController.view addSubview: self.cameraView.view];
//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"ceshi" message:@"shide " preferredStyle:UIAlertControllerStyleAlert];
//    [self presentViewController:alertController animated:YES completion:nil];
   
zhu's avatar
zhu committed
121
}
zhu's avatar
zhu committed
122 123 124 125 126 127
//场景赋图回调
- (void)resetSuperBackGroundImage:(UIImage*)image
{
    self.backGroundImageView.image=image;
}
//产品附图回调
zhu's avatar
zhu committed
128
- (void)resetSubProductImage:(UIImage*)image productModel:(NSMutableArray *)productModel
zhu's avatar
zhu committed
129 130
{
    ImageCropperView *cropper=[[ImageCropperView alloc]initWithFrame:CGRectMake(400, 300, 300, 300)];
zhu's avatar
zhu committed
131 132 133
//    cropper.layer.borderWidth = 1.0;
//    cropper.layer.borderColor = [UIColor blueColor].CGColor;
    
zhu's avatar
zhu committed
134 135 136
    cropper.image = image;
    [self.view addSubview:cropper];
}
zhu's avatar
zhu committed
137 138 139 140 141 142
//场景库选图回调
- (void)addSeceneImage:(UIImage *)image
{
    [self.footSubView addFootSubViewImage:image];
}
//产品库选图回调
zhu's avatar
zhu committed
143
- (void)addProductImage:(UIImage *)image productModel:(TOGoodsEntity *)productModel
zhu's avatar
zhu committed
144
{
zhu's avatar
zhu committed
145
    [self.rightSubView addRightSubViewImage:image productModel:productModel];
zhu's avatar
zhu committed
146
}
zhu's avatar
zhu committed
147 148 149 150 151 152
//分享回调
- (void)ShareProductImage:(UIImage *)image
{
    //    先截屏 并保存图片
    [self savePhoto];
}
zhu's avatar
zhu committed
153
//全屏
zhu's avatar
zhu committed
154 155
-(void)setViewAnimations:(UIButton *)sender
{
zhu's avatar
zhu committed
156 157 158 159 160 161 162
    self.zoomButton=sender;
    self.zoomButton.hidden=YES;
    self.temporaryBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    self.temporaryBtn.frame=sender.frame;
    [self.temporaryBtn setBackgroundImage:[UIImage imageNamed:@"xiaoping"] forState:UIControlStateNormal];
    [self.temporaryBtn addTarget:self action:@selector(resetViewDidSelected:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.temporaryBtn];
zhu's avatar
zhu committed
163

zhu's avatar
zhu committed
164
    [UIView beginAnimations:@"quanping" context:nil];
zhu's avatar
zhu committed
165 166
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:1.0f];
zhu's avatar
zhu committed
167 168 169
    self.leftSubView.frame=CGRectMake(-200, 0, 200, ScreenHeight-150);
    self.rightSubView.frame=CGRectMake(ScreenWidth, 0, 200, ScreenHeight-150);
    self.footSubView.frame=CGRectMake(0, ScreenHeight, ScreenWidth, 150);
zhu's avatar
zhu committed
170
    self.temporaryBtn.frame=CGRectMake(sender.frame.origin.x, 20, sender.frame.size.width, sender.frame.size.height);
zhu's avatar
zhu committed
171 172 173 174
    [UIView commitAnimations];
}
-(void)resetViewDidSelected:(UIButton *)sender
{
zhu's avatar
zhu committed
175 176
    [sender setBackgroundImage:[UIImage imageNamed:@"quanping"] forState:UIControlStateNormal];
    [UIView beginAnimations:@"xiaoping" context:nil];
zhu's avatar
zhu committed
177
    [UIView setAnimationDelegate:self];
zhu's avatar
zhu committed
178
    [UIView setAnimationDidStopSelector:@selector(animationFinish)];
zhu's avatar
zhu committed
179
    [UIView setAnimationDuration:1.0f];
zhu's avatar
zhu committed
180 181 182
    self.leftSubView.frame=CGRectMake(0, 0, 200, ScreenHeight-150);
    self.rightSubView.frame=CGRectMake(ScreenWidth-200, 0, 200, ScreenHeight-150);
    self.footSubView.frame=CGRectMake(0, ScreenHeight-150, ScreenWidth, 150);
zhu's avatar
zhu committed
183
    sender.frame=self.zoomButton.frame;
zhu's avatar
zhu committed
184
    [UIView commitAnimations];
zhu's avatar
zhu committed
185 186 187 188 189 190
  
}
-(void)animationFinish
{
     self.zoomButton.hidden=NO;
    [self.temporaryBtn removeFromSuperview];
zhu's avatar
zhu committed
191
}
zhu's avatar
zhu committed
192 193 194
//添加场景
-(void)addSceneLibraryView
{
ZCJ's avatar
ZCJ committed
195

zhu's avatar
zhu committed
196 197 198 199
    self.seceneLibraryView=[[SeceneLibraryView alloc]init];
    self.seceneLibraryView.view.backgroundColor=[UIColor clearColor];
    self.seceneLibraryView.delegate=self;
    [self.view addSubview:self.seceneLibraryView.view];
zhu's avatar
zhu committed
200 201 202 203
}
//添加产品
-(void)addProductLibraryView
{
zhu's avatar
zhu committed
204
    self.productLibraryView=[[ProductLibraryView alloc]init];
ZCJ's avatar
ZCJ committed
205
    self.productLibraryView.view.backgroundColor=[UIColor clearColor];
zhu's avatar
zhu committed
206 207
    self.productLibraryView.delegate=self;
    [self.view addSubview:self.productLibraryView.view];
zhu's avatar
zhu committed
208
}
zhu's avatar
zhu committed
209 210 211 212 213 214 215 216 217 218
//添加购物车
-(void)addShoppingView
{
    self.shoppingView=[[ShoppingView alloc]init];
    self.shoppingView.view.backgroundColor=[UIColor clearColor];
    self.shoppingView.productModelArray=self.productModelArray;
//    self.shoppingView.delegate=self;
    [self.view addSubview:self.shoppingView.view];
    
}
zhu's avatar
zhu committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
// 保存图片到相册功能,ALAssetsLibraryiOS9.0 以后用photoliabary 替代,

-(void)savePhoto

{
    
    UIImage * image = [self captureImageFromView:self.view];
    [self saveImageToPhotos:image];
    //
    //    PhysicalAddress
    ////    * library = [ALAssetsLibrary new];
    //
    ////    NSData * data = UIImageJPEGRepresentation(image, 1.0);
    ////
    ////    [library writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:nil];
    
}
- (void)saveImageToPhotos:(UIImage*)savedImage

{
    UIImageWriteToSavedPhotosAlbum(savedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
    
}
// 指定回调方法

- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo

{
    
    NSString *msg = nil ;
    
    if(error != NULL){
        
        msg = @"保存图片失败" ;
        
    }else{
        
        msg = @"保存图片成功" ;
//        保存成功后添加到footview
        [self addSeceneImage:image];
        
    }
    
    
}
//截图功能

-(UIImage *)captureImageFromView:(UIView *)view

{
    
    CGRect screenRect = [view bounds];
    
    UIGraphicsBeginImageContext(screenRect.size);
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    [view.layer renderInContext:ctx];
    
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return image;
    
}

曹云霄's avatar
曹云霄 committed
286 287 288 289 290
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

ZCJ's avatar
ZCJ committed
291 292


曹云霄's avatar
曹云霄 committed
293 294 295 296 297 298 299 300 301 302 303
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end