基础知识2

动画效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
-(void)doChange:(id)sender
{
if(view2 == nil)
{
[self loadSec];
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:([view1 superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)forView : self.view cache:YES];
  
    if([view1 superview]!= nil)
{
[view1 removeFromSuperview];
[self.view addSubview:view2];
  
}else {
  
[view2 removeFromSuperview];
[self.view addSubview:view1];
}
[UIView commitAnimations];
}

Table View <UITableViewDateSource>

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
#pragma mark -
#pragma mark Table View Data Source Methods
//指定分区中的行数,默认为1
- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
return [self.listData count];
}
  
//设置每一行cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIndentifier = @"SimpleTableIndentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIndentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:SimpleTableIndentifier]
autorelease];
}
     UIImage *image = [UIImage imageNamed:@"13.gif"];
cell.imageView.image = image;
  
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
     cell.textLabel.font = [UIFont boldSystemFontOfSize:20];
  
     if(row < 5)
cell.detailTextLabel.text = @"Best friends";
else
    cell.detailTextLabel.text = @"friends";
return cell;
}

图像:如果设置图像,则它显示在文本的左侧

文本标签:这是单元的主要文本(UITableViewCellStyleDefault 只显示文本标签)

详细文本标签:这是单元的辅助文本,通常用作解释性说明或标签

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
44
UITableViewCellStyleSubtitle
UITableViewCellStyleDefault
UITableViewCellStyleValue1
UITableViewCellStyleValue2
  
<UITableViewDelegate>
#pragma mark -
#pragma mark Table View Delegate Methods
//把每一行缩进级别设置为其行号
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
return row;
}
//获取传递过来的indexPath值
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
if (row == 0)
return nil;
return indexPath;
}
  
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
NSString *rowValue = [listData objectAtIndex:row];
NSString *message = [[NSString alloc] initWithFormat:@"You selected %@",rowValue];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Row Selected"
message:message
    delegate:nil
  cancelButtonTitle:@"Yes, I did!"
  otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
  
//设置行的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40;
}

随机数的使用

1
2
3
4
5
6
7
8
头文件的引用
#import <time.h>
#import <mach/mach_time.h>
 
srandom()的使用
srandom((unsigned)(mach_absolute_time() & 0xFFFFFFFF));
 
直接使用 random() 来调用随机数

在UIImageView 中旋转图像

1
2
3
float rotateAngle = M_PI;
CGAffineTransform transform =CGAffineTransformMakeRotation(rotateAngle);
imageView.transform = transform;

以上代码旋转imageView, 角度为rotateAngle, 方向可以自己测试哦!

posted @ 2015-03-01 11:42  被阳光素描  阅读(80)  评论(0编辑  收藏  举报