当前位置:  编程技术>移动开发
本页文章导读:
    ▪Java I/O源-ObjectInputStream、ObjectOutputStream        Java I/O流-ObjectInputStream、ObjectOutputStream一、整体代码       ObjectStreamDemo.java import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; im.........
    ▪ UIView详解二        UIView详解2第三、Configuring the Event-Related Behavior 1.  userInteractionEnabled  property A Boolean value that determines whether user events are ignored and removed from the event queue. @property(nonatomic, getter=isUserInteractionEnable.........
    ▪ UIView详解三       UIView详解3第四、调整大小的相关属性或函数(Configuring the Resizing Behavior) 1. autoresizingMask  property  概属性用来指出当父窗口发生变化时,子窗口应该如何变   如果视图的autoresizesSubviews.........

[1]Java I/O源-ObjectInputStream、ObjectOutputStream
    来源: 互联网  发布时间: 2014-02-18
Java I/O流-ObjectInputStream、ObjectOutputStream

一、整体代码

      ObjectStreamDemo.java

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;



public class ObjectStreamDemo {

    /**
     * 文件转化为Object
     * @param fileName
     * @return byte[]
     */
    public static Object file2Object(String fileName) {

        FileInputStream fis = null;
        ObjectInputStream ois = null;
        try {
            fis = new FileInputStream(fileName);
            ois = new ObjectInputStream(fis);
            Object object = ois.readObject();
            return object;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            if (ois != null) {
                try {
                    ois.close();
                } catch (IOException e2) {
                    e2.printStackTrace();
                }
            }
        }
        return null;
    }

    /**
     * 把Object输出到文件
     * @param obj
     * @param outputFile
     */
    public static void object2File(Object obj, String outputFile) {
        ObjectOutputStream oos = null;
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(new File(outputFile));
            oos = new ObjectOutputStream(fos);
            oos.writeObject(obj);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (oos != null) {
                try {
                    oos.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e2) {
                    e2.printStackTrace();
                }
            }
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) {

        String fileName = "1.txt";
        UserVo vo = new UserVo("michael", "大大", 18, new Date());

        ObjectStreamDemo.object2File(vo, fileName);
        System.out.println("success write bean:UserVo to file.");

        UserVo tmpvo = (UserVo) ObjectStreamDemo.file2Object(fileName);
        System.out.println("read bean:UserVo from file get info : " + tmpvo);

    }

}
   

        UserVo.java

import java.io.Serializable;
import java.util.Date;

public class UserVo implements Serializable {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -6846034858002233878L;

    private String userId;

    private String userName;

    private int age;

    private Date born;

    public UserVo() {
    }

    public UserVo(String userId, String userName, int age, Date born) {
        this.userId = userId;
        this.userName = userName;
        this.age = age;
        this.born = born;
    }

    /**
     * @return the userId
     */
    public String getUserId() {
        return userId;
    }

    /**
     * @return the userName
     */
    public String getUserName() {
        return userName;
    }

    /**
     * @return the age
     */
    public int getAge() {
        return age;
    }

    /**
     * @return the born
     */
    public Date getBorn() {
        return born;
    }

    /**
     * @param pUserId the userId to set
     */
    public void setUserId(String pUserId) {
        userId = pUserId;
    }

    /**
     * @param pUserName the userName to set
     */
    public void setUserName(String pUserName) {
        userName = pUserName;
    }

    /**
     * @param pAge the age to set
     */
    public void setAge(int pAge) {
        age = pAge;
    }

    /**
     * @param pBorn the born to set
     */
    public void setBorn(Date pBorn) {
        born = pBorn;
    }

    @Override
    public String toString() {
        return "userId=[ " + userId + " ] userName=[ " + userName + " ] age=[ "
                + age + " ] born=[ " + born + "] .";
    }

}


二、解释

       

         代码地址:https://github.com/jltxgcy/Demo




    
[2] UIView详解二
    来源: 互联网  发布时间: 2014-02-18
UIView详解2

第三、Configuring the Event-Related Behavior

1.  userInteractionEnabled  property

A Boolean value that determines whether user events are ignored and removed from the event queue.

@property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled

最简单的比如说让给一个button在点击时,没有响应,可以设置这个值为no

2.  multipleTouchEnabled  property

A Boolean value that indicates whether the receiver handles multi-touch events.

@property(nonatomic, getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled

Discussion

When set to YES, the receiver receives all touches associated with a multi-touch sequence. When set toNO, the receiver receives only the first touch event in a multi-touch sequence. The default value of this property isNO.

Other views in the same window can still receive touch events when this property isNO. If you want this view to handle multi-touch events exclusively, set the values of both this property and theexclusiveTouch property to YES.

3.   exclusiveTouch  property

A Boolean value that indicates whether the receiver handles touch events exclusively.

第四

1.frame:

描述当前视图在其父视图中的位置和大小,用位置坐标和长度来表示:

sample:

UIButton *button3=[[[UIButtonalloc] initWithFrame:CGRectMake(120,120, 100,100)] autorelease];

    button3.backgroundColor=[UIColorgreenColor];

    [self.view addSubview:button3];

    NSLog(@"the result is %f,%f,%f,%f",button3.frame.size.height,button3.frame.size.width,button3.frame.origin.x,button3.frame.origin.y);

结果:

the result is 100.000000,100.000000,120.000000,120.000000

2. bounds  property

描述当前视图在其自身坐标系统中的位置和大小。

iphone中坐标系统的建立,最左上角是原点(0,0),向右为x轴递增,想下为y轴递减。

ios采用CGPoint来表示点在坐标系上X、Y位置。我们可以通过CGPointMake(x,y)来创建一个坐标点:CGPoint point = CGPointMake(80,40)

同时,ios采用CGSize来表示视图的宽度和高度,即视图的大小。我们可以通过CGSizeMake(width,height)来创建一个矩形的大小,如CGSize size = CGSizeMake(144,72)将创建一个宽度为144,高度为72的矩形大小。

而CGRect则是结合了CGPoint和CGSize,用来表示矩形的位置和大小。它的origin表示矩形右上角所在位置(CGPoint),size表示矩形的大小(CGSize)。

sample:

  UIButton *button3=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 100, 100)] autorelease];
    button3.backgroundColor=[UIColor greenColor];
    [self.view addSubview:button3];
    NSLog(@"the result is %f,%f,%f,%f",button3.frame.size.height,button3.frame.size.width,button3.frame.origin.x,button3.frame.origin.y);
    
    NSLog(@"the result is %f,%f,%f,%f",button3.bounds.origin.x,button3.bounds.origin.y,button3.bounds.size.height,button3.bounds.size.width);
}

3.center  property

描述当前视图的中心点在其父视图中的位置。

sample如下所示:

    UIButton *button3=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 100, 100)] autorelease];
    button3.backgroundColor=[UIColor greenColor];
    [self.view addSubview:button3];
    NSLog(@"the result is %f,%f",button3.center.x,button3.center.y);
result is:

the result is 170.000000,170.000000

4.frame.bounds 和center的区别和联系

这两个属性都是用来描述视图的大小(CGSize)和位置(CGPoint)的,两者都用CGRect表示。不同的是,frame描述的是在其父视图中的CGRect,而bounds描述的是在其自身视图中的CGRect,

center属性则用CGPoint表示矩形中心点在其父视图中的位置,如图3中View B的center属性为(300,200)。

frame、bounds和center三个属性是相互关联、相互影响的,其中一个属性发生变化,其他属性也会跟着变化。



    
[3] UIView详解三
    来源: 互联网  发布时间: 2014-02-18
UIView详解3

第四、调整大小的相关属性或函数(Configuring the Resizing Behavior)

1. autoresizingMask  property

 概属性用来指出当父窗口发生变化时,子窗口应该如何变

  如果视图的autoresizesSubviews属性声明被设置为YES,则其子视图会根据autoresizingMask属性的值自动进行尺寸调整。简单配置一下视图的自动尺寸调整掩码常常就能使应用程序得到合适的行为;否则,应用程序就必须通过重载layoutSubviews方法来提供自己的实现。

2. autoresizesSubviews  property
返回值为true或false,表示当父窗口发生变化时,子窗口是否应该变化

3.  contentMode  property

主要用在UIImageView,当窗口大小和图片大小不一样时,通过该字段选择合适的布局方式。

4. – sizeThatFits:

Asks the view to calculate and return the size that best fits its subviews.

- (CGSize)sizeThatFits:(CGSize)size
Parameters size

The current size of the receiver.

Return Value

A new size that fits the receiver’s subviews.

5. – sizeToFit

Resizes and moves the receiver view so it just encloses its subviews.

- (void)sizeToFit得到最适合当前字数的尺寸,
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 20)];
    label.backgroundColor = [UIColor blueColor];
    label.text = @"fdsafasfsaaaaaaaaaaaaaa";
    [self.view addSubview:label];
    NSLog(@"bounds %@",NSStringFromCGRect(label.frame));
    [label sizeToFit];
    NSLog(@"bounds is %@",NSStringFromCGRect(label.frame));
返回结果是:

2013-09-02 18:39:16.284 single[1494:c07] bounds {{0, 0}, {70, 20}}

2013-09-02 18:39:16.285 single[1494:c07] bounds is {{0, 0}, {201, 21}}

第五、Laying out Subviews

1. – layoutSubviews

这个方法是当你需要在调整subview的大小的时候需要重写(我这个翻译不严谨,以下是原文:You should override this method only if the autoresizing behaviors of the subviews do not offer the behavior you want.),但有时候经常指望它被调用的时候没被调用,不希望它被调用的时候被调用了,搞的很上火。根据国外社区一个人帖子,做了总结性翻译。

layoutSubviews在以下情况下会被调用:

1、init初始化不会触发layoutSubviews

2、addSubview会触发layoutSubviews

3、设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化

4、滚动一个UIScrollView会触发layoutSubviews

5、旋转Screen会触发父UIView上的layoutSubviews事件

6、改变一个UIView大小的时候也会触发父UIView上的layoutSubviews事件

2. – setNeedsLayout

3. – layoutIfNeeded

-setNeedsLayout方法: 标记为需要重新布局,异步调用layoutIfNeeded刷新布局,不立即刷新,但layoutSubviews一定会被调用
-layoutIfNeeded方法:如果,有需要刷新的标记,立即调用layoutSubviews进行布局(如果没有标记,不会调用layoutSubviews)

如果要立即刷新,要先调用[view setNeedsLayout],把标记设为需要布局,然后马上调用[view layoutIfNeeded],实现布局

在视图第一次显示之前,标记总是“需要刷新”的,可以直接调用[view layoutIfNeeded]





    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3