2016-12-17 22:35:57 CJXBShowZhouyujuan 阅读数 2290

项目需求:
在网络上加载一组图片的数据,并且这组图片要按照比例展示出来

做法分析:

(1)首页界面上要是使用的图片控件的创建,这里的高度是用设定的高度,这部分需要在主线程完成;
(2)第二部部分是获取图片的实际尺寸,这部分在线程中完成;
(3)然后需要在主线程刷新frame,并使用sdweb加载图片
参考的网址:
dispatch_group
http://blog.csdn.net/yaoliangjun306/article/details/51462444

dispatch_group_enter
http://blog.csdn.net/u011103194/article/details/50248807

根据Url获取图片的尺寸
http://www.oschina.net/code/snippet_2248391_53038

- (float)createImageView:(NSArray *)imageArray directionStr:(NSString *)str{

    [self removeAllSubviews];

    __block CGFloat allHeight = 0;

    dispatch_queue_t queue = dispatch_get_global_queue(0, 0);

    dispatch_group_t group =dispatch_group_create();

    for (int i = 0; i < [imageArray count]; i++) {

第一步:先创建一个固定高度的View,ImageView

        CGFloat showImageH = 600;//自定义图片高度

        //背景View

        UIView * backImageView = [[UIView alloc]initWithFrame:CGRectMake(0,showImageH * i,_houseFrame.size.width, showImageH)];
        backImageView.backgroundColor = [UIColor whiteColor];


        //ImageView

        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,_houseFrame.size.width, showImageH)];

        [backImageView addSubview:imageView];
        [self addSubview:backImageView];

        showImageH = imageView.origin.y + imageView.height;

        //imageView属性的设置

        imageView.contentMode = UIViewContentModeScaleToFill;
        imageView.userInteractionEnabled = YES;


        //需要用到的Image的Url

        NSString *urlStr_S = [NSString stringWithFormat:@"%@%@",ImageHeaderURL,imageArray[i]];

        NSURL * urlImage = [NSURL URLWithString:urlStr_S];

第二步:根据图片的URl获取图片的真是尺寸        
       //这里使用group 
        dispatch_group_async(group, queue, ^{

  //这里是获取图片尺寸的方法
            CGSize  size = [Helper getImageSizeWithURL:urlImage];

            CGFloat a = size.width;
            CGFloat b = size.height;
            CGFloat space = 2;

            if(a > _houseFrame.size.width){

                a = _houseFrame.size.width;
                b = size.height*(_houseFrame.size.width)/size.width;
            }

 第三步:在group中使用异步请求是会有问题的,这是因为要刷新主界面了           dispatch_sync(dispatch_get_main_queue(), ^{

                //NSLog(@"main-------i----%d",i);
                [imageView setFrame:CGRectMake(0, 0, a, b)];
                [backImageView setFrame:CGRectMake(0, allHeight, _houseFrame.size.width, b)];
                allHeight+=b+space;
                [self setFrame:CGRectMake(0, 0, _houseFrame.size.width, allHeight)];


            });
    //使用sdwebImage加载图片        
             [imageView sd_setImageWithURL:urlImage];

        });

    }

//等到所有的图片的高度都计算完成了,返回界面刷新高度
    dispatch_group_notify(group, queue, ^{
      //NSLog(@"dispatch_group_notify-------i----");
        if(self.changeHouseType){
            //查看VR和方向的高度
            self.changeHouseType(allHeight);
        }
    });
    return allHeight;
}
2019-11-13 21:42:20 chuanyue11 阅读数 80

IOS图片生成工具(@1X,@2X,@3X)

在进行IOS开发过程中,经常需要为了适配不同分辨率的设备而准备不同尺寸的图片。由于本人长期从事后台研发工作,对前端及UI常用工具(比如PS)并不熟悉,于是开发了下面这个工具对一个大尺寸的图片进行裁剪,生成1倍、2倍、3倍尺寸的图片,方便进行IOS开发。

工具介绍

该工具接受两个参数,分别为源图片文件或目录和目标图片存放文件夹。源图片为分辨率高于所有裁剪结果图片的分辨率(@1X,@2X,@3X)。

裁剪结果图片的尺寸写在ResizeImage类开头处,可以根据需要进行修改。

工具代码

package tools;

import common.Base;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Arrays;

/**
 * Genarate @1X, @2X, @3X pictures.
 *
 * @author zjm
 */
public class ResizeImage extends Base {
    private static final Logger LOGGER = LoggerFactory.getLogger(ResizeImage.class);

    /**
     * {width, height}
     */
    //    private static final int[] SIZE_3X = new int[] { 300, 402 };
    //    private static final int[] SIZE_2X = new int[] { 200, 268 };
    //    private static final int[] SIZE_1X = new int[] { 100, 134 };
    private static final int[] SIZE_3X = new int[] { 300, 300 };
    private static final int[] SIZE_2X = new int[] { 200, 200 };
    private static final int[] SIZE_1X = new int[] { 100, 100 };

    private String srcFileOrDirctory;
    private String destDirectory;

    public ResizeImage() {

    }

    public ResizeImage(String srcFileOrDirctory, String destFileOrDirectory) {
        this.srcFileOrDirctory = srcFileOrDirctory;
        this.destDirectory = destFileOrDirectory;
    }

    public String getSrcFileOrDirctory() {
        return srcFileOrDirctory;
    }

    public void setSrcFileOrDirctory(String srcFileOrDirctory) {
        this.srcFileOrDirctory = srcFileOrDirctory;
    }

    public String getDestDirectory() {
        return destDirectory;
    }

    public void setDestDirectory(String destDirectory) {
        this.destDirectory = destDirectory;
    }

    public void resizeImage() throws Exception {
        LOGGER.debug("Resize image parameters: src - {}, dest - {}", srcFileOrDirctory, destDirectory);

        File src = new File(srcFileOrDirctory);

        File dest = new File(destDirectory);
        if (dest.exists() && dest.isFile()) {
            throw new IllegalArgumentException("Not a directory: " + dest);
        }
        dest.mkdirs();

        if (src.exists() && src.isDirectory()) {
            File[] images = src.listFiles();
            for (File image : images) {
                resizeImage(srcFileOrDirctory, destDirectory);
            }
        } else if (src.exists() && src.isFile()) {
            resizeImage(srcFileOrDirctory, destDirectory);
        } else {
            throw new IllegalArgumentException("No such file or directory: " + src);
        }
    }

    private void resizeImage(String src, String dest) throws Exception {
        File destImage;

        destImage = new File(dest, getTypePrefix(src) + "@3X." + getTypeAppendix(src));
        resizeImage(src, destImage.getAbsolutePath(), SIZE_3X);

        destImage = new File(dest, getTypePrefix(src) + "@2X." + getTypeAppendix(src));
        resizeImage(src, destImage.getAbsolutePath(), SIZE_2X);

        destImage = new File(dest, getTypePrefix(src) + "@1X." + getTypeAppendix(src));
        resizeImage(src, destImage.getAbsolutePath(), SIZE_1X);
    }

    private void resizeImage(String src, String dest, int[] size) throws Exception {
        LOGGER.debug("Resizing image {} to {} in size {} ...", src, dest, Arrays.toString(size));

        BufferedImage srcImage = ImageIO.read(new File(src));

        BufferedImage destImage = new BufferedImage(size[0], size[1], srcImage.getType());
        Graphics2D destGraph = destImage.createGraphics();
        destGraph.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        destGraph.drawImage(srcImage, 0, 0, size[0], size[1], 0, 0, srcImage.getWidth(), srcImage.getHeight(), null);
        destGraph.dispose();

        ImageIO.write(destImage, getTypeAppendix(src), new File(dest));

        LOGGER.debug("A new image {} is created.", dest);
    }

    private String getTypeAppendix(String image) {
        int lastIndex = image.lastIndexOf(".");
        return image.substring(lastIndex + 1);
    }

    private String getTypePrefix(String image) {
        int lastSlashIndex = image.lastIndexOf("/");
        int lastDotIndex = image.lastIndexOf(".");
        return image.substring(lastSlashIndex + 1, lastDotIndex);
    }

    public static void main(String[] args) throws Exception {
        if (args.length != 2) {
            LOGGER.error("Invalid arguments. Usage: {} <source image file or directory> <dest image directory>",
                    ResizeImage.class.getSimpleName());
            System.exit(1);
        }
        new ResizeImage(args[0], args[1]).resizeImage();
    }
}

2019-01-15 17:42:12 lpCrazyBoy 阅读数 450

1、AppIcon 尺寸

iPhone Notification iOS 7-10 20pt                             2x( 40x40 )  3x( 60x60 )

iPhone、Spotlight iOS 5,6 、Settings iOS 5-10  29pt   2x( 58x58 )  3x( 87x87 )

iPhone Spotlight iOS 7-10 40pt                                 2x( 80x80 )   3x( 120x120 )

iPhone APP iOS 7-10 60pt                                        2x( 120x120 )  3x( 180x180 )

iPad Notifications 7-10 20pt                                      1x( 20x20 )  2x( 40x40 )

iPad Settings 5-10 29pt                                            1x( 29x29 )  2x( 58x58 )

iPad Spotlight iOS 7-10 40pt                                     1x( 40x40 )  2x( 80x80 )

iPad App iOS 7-10 76pt                                            1x( 76x76 )  2x( 152x152 )

iPad Pro App iOS 9-10 83.5                                      2x( 167x167 )

 

2、LaunchImage尺寸

iPhone X  1125 * 2436  必要

iPhone Portrait  iOS 5,6        1x( 320x480 )  2x( 640x960 ) Retina4( 640x1136 )

iPhone Portrait iOS 8,9         Retina HD 5.5( 1242x2208 )  Retina HD 4.7( 750x1334 )  必要

iPhone Portrait iOS 7-9        2x( 640x960 )  Retina4( 640x1136 )  必要(没有的话 在5上边有问题)

iPhone Landscape iOS 8,9    Retina HD 5.5( 2208x1242 )

 

iPad Portrait iOS 5,6            1x( 768x1024 )  2x( 1536x2048 )

iPad Portait iOS 7-9            1x( 768x1024 )  2x( 1536x2048 )

iPad Landscape iOS 5,6       1x( 1024x768 )  2x( 2048x1536 )

iPad Landscape 7-9            1x( 1024x768 )  2x( 2048x1536 )

iPad Portrait Without Status Bar iOS 5,6           1x( 768x1004 )  2x( 1536x2008 )

iPad Landscape Without Status Bar iOS 5,6      1x( 1024x748 )  2x( 2048x1496 )

2016-11-18 15:44:41 qq_22746575 阅读数 218

总结了一下ios里面的尺寸问题

1.launchimage 尺寸


LaunchScreen.xib可以作为launchimage,但是只适用于iOS8以上(现在估计都是ios8以上的开发了,ios7快被抛弃了,尤其是用swift开发的,ios7已经被抛弃了)

2.APPicon 尺寸



3.手机页面尺寸(借图一张)




4.不同手机屏幕高度尺寸

 iPhone6/6s/7 = 667.0 

 iPhone6/7plus = 736.0

 iPhone 5/5s/5c  = 568.0 

 iPhone4s = 480.0




附上我常用的 图标下载地址: http://www.iconfont.cn/collections


2017-03-30 10:18:20 abvedu 阅读数 433



启动图片是iOS加载App的时候系统响应的直观呈现。近几年,随着屏幕尺寸的增多,制作相应的静态图片就变成一件十分让人头疼的事。下面是一些竖屏的启动图片的尺寸(尺寸包括状态条区域):

iPad 2 and iPad mini (@1x): 768 x 1024

iPad and iPad mini (retina @2x): 1536 x 2048

iPhone 4s (retina @2x) 640 x 960

iPhone 5 (@2x): 640 x 1136

iPhone 6 (@2x): 750 x 1334

iPhone 6 Plus (@3x): 1242 x 2208


没有更多推荐了,返回首页