存根Activity,用这个Activity来加载其他的Activity,为了重复使用Activity使用,它的子类必须实现onCreate()方法。可以在onCreate()方法中调用finish()方法,这时Activity跳过生命周期直接调用onDestroy()方法。
activity-alias具体属性有:

  • android:targetActivity 目标Activity,这个属性的值必须是声明
  • android:name alias的唯一标识
  • android:enabled 是否运行aliasActivity加载targetActivity,缺省为true
  • android:exported 是否运行其他的Application通过使用aliasActivity来加载targetActivity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<activity
android:name="com.example.aliasactivitydemo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias
android:name="AndroidAlias"
android:targetActivity="MainActivity"
android:label="Alias"
android:icon="@drawable/ic_launcher">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>

示例



ExpendableListActivity

一个具有可展开list,其中的item通过ExpandableListAdapter接口来绑定数据源。当用户选择其中某一项时可以自己去定义处理方法。ExpendableListActivity含有一个ExpandableView对象,用两层的方法来展示数据,第一层是组,第二层是子项。使用自定义的xml来制定布局,则ExpandableListView一定要用”@id/android:list”作为id,另外使用一个id@“@id/android/empty”来表示空的list.

main.xml

1
2
3
4
5
6
7
8
9
10
11
12
<ExpandableListView 
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"
/>
<TextView
android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No data"/>

child.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/child"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="50px"
android:paddingTop="5px"
android:paddingBottom="5px"
android:textSize="20px"
android:text="NO data"/>

</LinearLayout>

group.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/group"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="60px"
android:paddingTop="10px"
android:paddingBottom="10px"
android:textSize="26px"
android:text="No data"
/>
</LinearLayout>

MainActivity.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
List<Map<String,String>> groups = new ArrayList<Map<String,String>>();
Map<String, String> group1 = new HashMap<String, String>();
Map<String, String> group2 = new HashMap<String, String>();
group1.put("group", "DOTA");
group2.put("group","DiaBlo");
groups.add(group1);
groups.add(group2);
//
List<Map<String, String>> child1 = new ArrayList<Map<String,String>>();
Map<String, String> childData1 = new HashMap<String, String>();
Map<String, String> childData2 = new HashMap<String, String>();
childData1.put("child", "Dota1");
childData2.put("child", "Dota2");
child1.add(childData1);
child1.add(childData2);
//
List<Map<String, String>> child2 = new ArrayList<Map<String,String>>();
Map<String, String> child2Data1 = new HashMap<String, String>();
Map<String, String> child2Data2 = new HashMap<String, String>();
Map<String, String> child2Data3 = new HashMap<String, String>();
child2Data1.put("child", "DiaBlo1");
child2Data2.put("child", "DiaBlo2");
child2Data3.put("child", "DiaBlo3");
child2.add(child2Data1);
child2.add(child2Data2);
child2.add(child2Data3);
//
List<List<Map<String,String>>> childs = new ArrayList<List<Map<String,String>>>();
childs.add(child1);
childs.add(child2);
SimpleExpandableListAdapter adapter =
new SimpleExpandableListAdapter(
this, //context
groups, //一级目录数据
R.layout.group, //一级目录样式布局文件
new String[]{"group"}, //指定一级目录数据的key
new int[]{R.id.group}, //指定一级目录数据显示控件的id
childs, //二级目录的数据
R.layout.child, //二级目录样式布局文件
new String[]{"child"}, //指定二级目录数据的
new int[]{R.id.child} //指定二级目录数据显示控件的
);
setListAdapter(adapter);

示例


  1. 先创建一个NSURL
  2. 在通过NSURL创建NSURLRequest,可以指定缓存规则和超时时间
  3. 创建NSURLConnection实例,指定NSURLRequest和delegate对象,如果创建失败,则返回nil,如果创建成功则创建一个NSMutableData的实例用来存储数据。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
NSURLRequest *request = [NSUELRequest requestWithURL:[NSURL URLWithString:@"http://www.sina.com.cn/"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(connection){
// 创建成功
}
else{
// 创建失败
}

# pragma mark- NSUrlConnectionDelegate methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
//接受一个服务端回话,再次一般初始化接受数据的对象
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// 每个中间data
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// 连接结束

}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
// 链接错误
}

Shutdown命令,h/r/s分别代表关机、重启、睡眠,再加上执行时间(yymmddhhmm)即可

比如sudo shutdown -h 1404081900

1、常见的NSFileManager文件方法

-(NSData *)contentsAtPath:path  //从一个文件读取数据

-(BOOL)createFileAtPath: path contents:(NSData *)data attributes:attr  //向一个文件写入数据

-(BOOL)removeItemAtPath:path error:err  //删除一个文件

-(BOOL)moveItemAtPath:from toPath:to error:err  //重命名或者移动一个文件(to不能是已存在的)

-(BOOL)copyItemAtPath:from toPath:to error:err  //复制文件(to不能是已存在的)

-(BOOL)contentsEqualAtPath:path andPath:path2  //比较两个文件的内容

-(BOOL)fileExistAtPath:path  //测试文件是否存在

-(BOOL)isReadableFileAtPath:path  //测试文件是否存在,并且是否能执行读操作  

-(BOOL)isWriteableFileAtPath:path  //测试文件是否存在,并且是否能执行写操作  

-(NSDictionary *)attributesOfItemAtPath:path error:err  //获取文件的属性  

-(BOOL)setAttributesOfItemAtPath:attr error:err  //更改文件的属性

2.使用目录

-(NSString *)currentDirectoryPath  //获取当前目录

-(BOOL)changeCurrentDirectoryPath:path  //更改当前目录

-(BOOL)copyItemAtPath:from toPath:to error:err  //复制目录结构(to不能是已存在的)

-(BOOL)createDirectoryAtPath:path withIntermediateDirectories:(BOOL)flag attribute:attr  //创建一个新目录

-(BOOL)fileExistAtPath:path isDirectory:(BOOL*)flag  //测试文件是不是目录(flag中储存结果YES/NO)

-(NSArray *)contentsOfDirectoryAtPath:path error:err  //列出目录内容

-(NSDirectoryEnumerator *)enumeratorAtPath:path  //枚举目录的内容

-(BOOL)removeItemAtPath:path error:err  //删除空目录

-(BOOL)moveItemAtPath:from toPath:to error:err   //重命名或移动一个目录(to不能是已存在的)

3、常用路径工具方法

+(NSString *)pathWithComponens:components  //根据components中的元素构造有效路径

-(NSArray *)pathComponents  //析构路径,获得组成此路径的各个部分

-(NSString *)lastPathComponent  //提取路径的最后一个组成部分

-(NSString *)pathExtension  //从路径的最后一个组成部分中提取其扩展名

-(NSString *)stringByAppendingPathComponent:path  //将path添加到现有路径的末尾

-(NSString *)stringByAppendingPathExtension:ext  //将指定的扩展名添加到路径的最后一个组成部分

-(NSString *)stringByDeletingLastPathComponent  //删除路径的最后一个组成部分

-(NSString *)stringByDeletingPathExtension  //从文件的最后一部分删除扩展名

-(NSString *)stringByExpandingTileInPath   //将路径中代字符扩展成用户主目录()或指定用户的主目录(user)

-(NSString *)stringByresolvingSymlinksInPath  //尝试解析路径中的符号链接

-(NSString *)stringByStandardizingPath  //通过尝试解析~、..(父目录符号)、.(当前目录符号)和符号链接来标准化路径

4、常用的路径工具函数

NSString* NSUserName(void)  //返回当前用户的登录名

NSString* NSFullUserName(void)  //返回当前用户的完整用户名

NSString* NSHomeDirectory(void)  //返回当前用户主目录的路径

NSString* NSHomeDirectoryForUser(NSString* user)  //返回用户user的主目录

NSString* NSTemporaryDirectory(void)  //返回可用于创建临时文件的路径目录

5、常用的IOS目录

Documents(NSDocumentDirectory)  //用于写入应用相关数据文件的目录,在ios中写入这里的文件能够与iTunes共享并访问,存储在这里的文件会自动备份到云端

Library/Caches(NSCachesDirectory)  //用于写入应用支持文件的目录,保存应用程序再次启动需要的信息。iTunes不会对这个目录的内容进行备份

tmp(use NSTemporaryDirectory())  //这个目录用于存放临时文件,只程序终止时需要移除这些文件,当应用程序不再需要这些临时文件时,应该将其从这个目录中删除

Library/Preferences  //这个目录包含应用程序的偏好设置文件,使用 NSUserDefault类进行偏好设置文件的创建、读取和修改

在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高。

1
2
3
4
5
6
7
8
9
enum {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};

UIViewAutoresizingNone就是不自动调整。
UIViewAutoresizingFlexibleLeftMargin 自动调整与superView左边的距离,保证与superView右边的距离不变。
UIViewAutoresizingFlexibleRightMargin 自动调整与superView的右边距离,保证与superView左边的距离不变。
UIViewAutoresizingFlexibleTopMargin 自动调整与superView顶部的距离,保证与superView底部的距离不变。
UIViewAutoresizingFlexibleBottomMargin 自动调整与superView底部的距离,也就是说,与superView顶部的距离不变。
UIViewAutoresizingFlexibleWidth 自动调整自己的宽度,保证与superView左边和右边的距离不变。
UIViewAutoresizingFlexibleHeight 自动调整自己的高度,保证与superView顶部和底部的距离不变。
UIViewAutoresizingFlexibleLeftMargin |UIViewAutoresizingFlexibleRightMargin 自动调整与superView左边的距离,保证与左边的距离和右边的距离和原来距左边和右边的距离的比例不变。

PendulemView

1
2
3
pendulum = [[PendulumView alloc] initWithFrame:self.view.bounds ballColor:ballColor ballDiameter:35];
pendulum.hidesWhenStopped = NO;
[self.view addSubview:pendulum];

SONFillAnimation是将一个UIView以指定网格动画显示的类。

用法

1
2
3
4
5
6
SONFillAnimation *animation = [[SONFillAnimation alloc] initWithNumberOfRows:3 columns:3 animationType:SONFillAnimationTypeDefault];
animation.direction = SONFillAnimationDirectionLeftToRightAndTopDown;
animation.duration = 0.3;
animation.xDelay = 0.1;
animation.yDelay = 0.2;
[animation animateView:view completion:^{}];

numberOfRows指行数,numberOfColumns指列数
xDelay指横向网格之间延迟的属性,yDelay指纵向网格之间延迟的属性
anchorPoint指定每个网格的锚点
direction指定顺序方向

您可以指定以下其中一个方向:

  • SONFillAnimationDirectionLeftToRightAndTopDown
  • SONFillAnimationDirectionLeftToRightAndBottomUp
  • SONFillAnimationDirectionRightToLeftAndTopDown
  • SONFillAnimationDirectionRightToLeftAndBottomUp
  • SONFillAnimationDirectionRandom

animationType是一个属性,表示一个类型的动画。

您可以指定在以下的animationType:

  • SONFillAnimationTypeDefault
  • SONFillAnimationTypeFoldOut
  • SONFillAnimationTypeFoldIn
  • SONFillAnimationTypeCustom

setRotationVector:::是定义为FoldIn/折页动画旋转向量的方法。如果动画类型是自定义的,就不需要设置这个值。默认值是(0,-1,0)。

在Podfile中添加

1
pod 'AVOSCloud'

使用UI相关的相关功能,就添加

1
pod 'AVOSCloundUI'

SNS组件的相关功能,就添加

1
pod 'AVOSCloundSNS'

AppDelegate.m文件,添加下列导入语句到头部

1
# import <AVOSClound/AVOSCloud.h>;

application:didFinishLaunchingWithOptions函数内添加

1
[AVOSClound setApplicationId:@"" clientKey:@""];

要跟踪应用的打开情况,添加下列代码

1
[AVAnalytics trackAppOpenedWithLaunchOptions:launchOptions];

对象

AVObject

在AVOS Cloud上,数据存储是围绕AVObject进行的。每个AVObject都包含了与JSON兼容的key-value对应的数据。数据是schema-free的,不需要在每个AVObject上提前制定存在哪些键,只要直接设定对应的key-value即可。
key必须是字母数字或下划线组成的字符串,自定义的键不能以__开头。值可以是字符串、数字、布尔值、甚至是数组和字典。
注意:在iOS SDK中,uuid是保留字段,不能作为key来使用。

保存对象

1
2
3
4
5
AVObject *gameScore = [AVObject objectWithClassName:@"GameScore"];
[gameScore setObject:[NSNumber numberWithInt:1337] forKey:@"score"];
[gameScore setObject:@"Steve" forKey:@"playerName"];
[gameScore setObject:[NSNumber numberWithBool:NO] forKey:@"cheatMode"];
[gameScore save];

setDesignResolutionSize(with,height,resolutionPolicy)
适配模式:

  • EXACT_FIT 游戏所有内容全部拉伸,内容铺满
  • NO_BORDER 一个方向上铺满屏幕
  • SHOW_ALL 保证设计区域全部显示,但是可能会有黑边
  • FIXED_WIDTH 保证设计分辨率的宽度不变,根据屏幕分辨率修正设计分辨率的高度
  • FIXED_HEIGHT 保证设计分辨率的高度不变,根据屏幕分辨率修正设计分辨率的宽度

NSUserDefaults类提供了一个与默认系统进行交互的编程接口。

使用

创建一个user defaults

1
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

添加数据

1
[userDefaults setObject:nameField.text forKey:UserDefayltNameKey];

也可以是基本数据类型int、float、bool等,有相应的方法

1
[userDefaults setBool:YES forKey:UserDefaultBoolKey];

读取数据

1
2
[userDefaults objectForKey:UserDefaultNameKey];
[userDefaults boolForKey:UserDefaultBoolKey];

注:NSUserDefaults非常好用,并不需要用户在程序中设置NSUserDefaults的全局变量,需要在哪里使用NSUserDefaults的数据,那么就在哪里创建一个NSUserDefaults对象,然后进行读或者写操作。
针对同一个关键字对应的对象或者数据,可以对它进行重写,重写之后关键字就对应新的对象或者数据,旧的对象或者数据会被自动清理。