demo2动态加载显示商品详情页

时间:2023-03-09 13:31:22
demo2动态加载显示商品详情页

demo2动态加载显示商品详情页demo2动态加载显示商品详情页

/*

要求:实现 头像+昵称(多余7位用...)

商品图片(根据商品实际的图片的大小进行动态的展示。按照一定的比例进行展示。)

产品简介。产品简介在商品图片的下边。并跟随商品图片的大小进行动态的收缩或者是展示。

考虑:实现功能之后,是否要做占位图 进行图片的占位??!

*/

难点:动态的加载。

实现:首先创建ui 然后请求数据 最后在主线程进行赋值 并且刷新ui 即可实现。

//

//  ACShowDetailVC.m

//  demo2详情动态加载展开

//

//  Created by Alice_ss on 2018/1/3.

//  Copyright © 2018年 AC. All rights reserved.

//

#import "ACShowDetailVC.h"

#import "JAppViewTools.h"

#import "JAppUtility.h"

#import "UIViewExt.h"

#import "AFNetworking.h"

#import "UIImageView+WebCache.h"

#define SCREENW [UIScreen mainScreen].bounds.size.width

#define SCREENH [UIScreen mainScreen].bounds.size.height

@interface ACShowDetailVC (){

    UIScrollView *bgScrollView;//最后边用一个scrollview比较方便

    UIView *contentView;//装内容的view

    UIImageView *iconIMG;

    UILabel *nicknameLabel;

    UIImageView *goodIMG;

    UILabel *goodIntro;

}

@end

@implementation ACShowDetailVC

- (void)viewDidLoad {

    [super viewDidLoad];

    [self createUI];

    //模拟请求数据

    [self performSelector:@selector(loadDates) withObject:nil afterDelay:2.0f];

}

#pragma mark - 模拟请求数据

- (void)loadDates{

    //请求完数据之后,从新绘制界面。

    //假如请求到了头像  昵称  商品图 商品描述

    [UIView animateWithDuration:1.0f animations:^{

        //在这里刷新主界面,展示新界面,在主线程中刷新ui

        dispatch_async(dispatch_get_main_queue(), ^{

            [self freshUI];

        });

    } completion:nil];

}

#pragma mark - 请求完数据之后从新刷新ui

- (void)freshUI{

    //设置内容

    [iconIMG sd_setImageWithURL:[NSURL URLWithString:@"https://tva2.sinaimg.cn/crop.0.0.100.100.50/0068QiKMjw8esxxwpxcxdj302s02s3yb.jpg"] placeholderImage:[UIImage imageNamed:@"icon_default"]];

    nicknameLabel.text = @"我是昵称。我的昵称是小可爱";

    [goodIMG sd_setImageWithURL:[NSURL URLWithString:@"https://tva2.sinaimg.cn/crop.0.0.100.100.50/0068QiKMjw8esxxwpxcxdj302s02s3yb.jpg"] placeholderImage:[UIImage imageNamed:@"icon_default"]];

    goodIntro.text = @"这个宝贝,人见人爱,花见花开。你一定会爱上她的。真的不信你看呀。我是一只宝贝详情,我是独一无二的存在。2018年一定要。。。。。。。。。。。。。。。。。。。。。。。。这个宝贝,人见人爱,花见花开。你一定会爱上她的。真的不信你看呀。我是一只宝贝详情,我是独一无二的存在。2018年一定要。。。。。。。。。。。。。。。。。。。。。。。。这个宝贝,人见人爱,花见花开。你一定会爱上她的。真的不信你看呀。我是一只宝贝详情,我是独一无二的存在。2018年一定要。。。。。。。。。。。。。。。。。。。。。。。。这个宝贝,人见人爱,花见花开。你一定会爱上她的。真的不信你看呀。我是一只宝贝详情,我是独一无二的存在。2018年一定要。。。。。。。。。。。。。。。。。。。。。。。。这个宝贝,人见人爱,花见花开。你一定会爱上她的。真的不信你看呀。我是一只宝贝详情,我是独一无二的存在。2018年一定要。。。。。。。。。。。。。。。。。。。。。。。。这个宝贝,人见人爱,花见花开。你一定会爱上她的。真的不信你看呀。我是一只宝贝详情,我是独一无二的存在。2018年一定要。。。。。。。。。。。。。。。。。。。。。。。。这个宝贝,人见人爱,花见花开。你一定会爱上她的。真的不信你看呀。我是一只宝贝详情,我是独一无二的存在。2018年一定要。。。。。。。。。。。。。。。。。。。。。。。。";

//    goodIntro.text = @"这个宝贝,人见人爱";

    //设置内容的位置及格式

    //1.名字最多显示8个字。多余的显示...

    if (nicknameLabel.text.length>8) {

        nicknameLabel.text = [[nicknameLabel.text substringWithRange:NSMakeRange(0, 7)]stringByAppendingString:@"..."];

    }

    //2.商品图片的高度按照比例进行显示

    [goodIMG sd_setImageWithURL:[NSURL URLWithString:@"https://tva2.sinaimg.cn/crop.0.0.100.100.50/0068QiKMjw8esxxwpxcxdj302s02s3yb.jpg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

        CGFloat scorW = goodIMG.width/image.size.width;

        CGFloat scroH = scorW *image.size.height;

        //从新设置goodimg的高度

        goodIMG.height = scroH;

        goodIntro.top = CGRectGetMaxY(goodIMG.frame)+10;

        goodIntro.height  = [JAppUtility getTextHeightWithView:goodIntro];

        contentView.height = CGRectGetMaxY(goodIntro.frame)+10;

        CGFloat offY =CGRectGetMaxY(contentView.frame)-SCREENH;

        NSLog(@"%f",offY);

        if(offY>0){

            bgScrollView.contentSize = CGSizeMake(SCREENW, SCREENH+offY+64);

        }else{

          bgScrollView.contentSize = CGSizeMake(SCREENW, SCREENH);

        }

    }];

}

#pragma mark - 界面ui

- (void)createUI{

//    self.view.backgroundColor = [UIColor grayColor];

    bgScrollView = [JAppViewTools getScrollView:CGRectMake(0, 64, SCREENW, SCREENH) :self];

    bgScrollView.contentSize = CGSizeMake(SCREENW, SCREENH);

    bgScrollView.backgroundColor = [UIColor grayColor];

    [self.view addSubview:bgScrollView];

    //1.大view

    contentView = [JAppViewTools getView:CGRectMake(0, 0, SCREENW, 300) :[UIColor whiteColor]];

    [bgScrollView addSubview:contentView];

    //2.头像

    iconIMG = [JAppViewTools getImageView:CGRectMake(15, 15, 44, 44) image:@"icon_default"];

    [contentView addSubview:iconIMG];

    //3.昵称

    nicknameLabel = [JAppViewTools getLabel:CGRectMake(CGRectGetMaxX(iconIMG.frame)+10, CGRectGetMidY(iconIMG.frame)-10, SCREENW-(CGRectGetMaxX(iconIMG.frame)+10), 20) :JTextFCMake([UIFont systemFontOfSize:15], [UIColor blackColor])];

    nicknameLabel.text = @"名字占位符";

    [contentView addSubview:nicknameLabel];

    //4.商品图

    goodIMG = [JAppViewTools getImageView:CGRectMake(CGRectGetMinX(iconIMG.frame), CGRectGetMaxY(iconIMG.frame)+10, SCREENW-CGRectGetMinX(iconIMG.frame)*2, 100) image:@"icon_default"];

    [contentView addSubview:goodIMG];

    //5.商品简介

    goodIntro = [JAppViewTools getLabel:CGRectMake(CGRectGetMinX(iconIMG.frame), CGRectGetMaxY(goodIMG.frame)+10, SCREENW-30, 30) :@"商品简介占位符" :JTextFCMake([UIFont systemFontOfSize:15], [UIColor redColor])];

    [contentView addSubview:goodIntro];

    contentView.height = CGRectGetMaxY(goodIntro.frame)+10;

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

/*

#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

喜欢的,想要demo的可以 邮箱联系我:673658917@qq.com.

如有任何问题,也可联系我邮箱,期待你。

业精于勤荒于嬉,行成于思毁于随。加油