分享

stupid教程

 许多润泽 2012-11-03
UILable

        
UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, 200, 20)];
//放的内容
lable.text = 
lable.tag = TITLELABLETAG;
//字体大小
lable.textColor = [UIColor colorWithRed:186.0/225 green:164.0/225 blue:115/225 alpha:1.0];
//背景颜色
lable.backgroundColor = [UIColor clearColor];
//放的位置
lable.textAlignment = UITextAlignmentCenter;
//字体大小
lable.font = [UIFont systemFontOfSize:20.0f];
[view addSubview:lable];



TableView



//要在头文件中实现UITableViewDelegate 和 UITableViewDataSource 协议 可以通过xib关联


//tableView 的方法 通过button 绑定的方法
-(void)edit{
//可以编译了 设过后系统就会调用下面的方法 
//- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
//- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
[_tableView setEditing:!_tableView.editing animated:YES];
}

//tableViewdelegate 
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
//编译风格 
return   UITableViewCellEditingStyleInsert;
}


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
// 交换行
//int row = [indexPath row];
//
// [_shuArray removeObjectAtIndex:row];
//
// NSArray *arr = [NSArray arrayWithObject:indexPath];
//
//
// [_tableView deleteRowsAtIndexPaths:arr withRowAnimation: UITableViewRowAnimationFade];
//
//int row = [indexPath row];
[_shuArray addObject:@"1"];
NSArray *arr = [NSArray arrayWithObject:indexPath];
[_tableView insertRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationFade];
NSLog(@"%d",[_shuArray count]);
}





- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
//删去行 先删数据 在删去行
NSArray *temp = [[_shuArray objectAtIndex:sourceIndexPath.row]retain];
//该过程是将_shuarray保存的对象的指针给了temp。但remove会将该对象给释放掉 所以需要retain一次
[_shuArray removeObjectAtIndex:sourceIndexPath.row];
[_shuArray insertObject:temp atIndex:destinationIndexPath.row];
[temp release];
}

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"return nil");
//将要选择那一行 先执行
if (indexPath.row < 2) 
{
NSString *message = [NSString stringWithFormat:@"你选择的是第%d行",[indexPath row]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"标题" message:message delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"ok",nil];
[alert show];
[alert release];
return nil;
}
else
{
return indexPath;
}

return 0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//已经选择那一行 后执行
}

#pragma mark -

#pragma mark UITableViewDataSource


//必须完成的UITableViewDataSource的方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//区数
return 1;

}            


- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{
//每一个区的行数
return [_shuArray count];
NSLog(@"(NSInteger)tableView");
}




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//创建可重复利用的cell indexPath 包括 row section 两个属性 就好像point一样
static NSString *CellIdentifier = @"Cell";
NSLog(@"本方法被调用了");
UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) 
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
NSLog(@"congjianle");
cell.imageView.image = [UIImage imageNamed:@"fo.png"];
cell.accessoryType =   UITableViewCellAccessoryDetailDisclosureButton;
        
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = [_shuArray objectAtIndex:indexPath.row];
    //设计选中的风格
   

return cell;
}
//用xib自定义cell
1。建立一个继承与uitableviewcell的基本的类
2。建立一个空的xib xib的属性为上面建立的uitableviewcell的基本的类并且设置他的Identifier(重复利用)标志Cell
3 。通过下面找到该cell

static NSString *CellIdentifier = @"Cell";
ZBYDishTableViewCell *cell =(ZBYDishTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) 
{
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"ZBYDishTableViewCell" owner:nil options:nil];
for (id  oneObject in array) 
{
if ([oneObject isKindOfClass:[ZBYDishTableViewCell class]]) 
{
cell = (ZBYDishTableViewCell *)oneObject;
break;
}
}
}

    return cell;




//设计均匀排部的button



int collInter=(320-3*buttonWidth)/4;
    int rowInter=(460-3*buttonHeight)/4;
    for (int i=0; i<9; i++) {
        int x=(i%3+1)*collInter+(i%3)*buttonWidth;
        int y=(i/3+1)*rowInter+(i/3)*buttonHeight;
        
        UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
        button.tag=i+1;
        button.frame=CGRectMake(x, y, buttonWidth, buttonHeight);
        NSString *Str=[[NSString alloc] initWithFormat:@"%d",i];
        [button setTitle:Str forState:  UIControlStateNormal ];
        [button addTarget:self action:@selector(whackMole:)forControlEvents: UIControlEventTouchUpInside];
        [self.view addSubview:button];


UINavigationBar



               UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 44)];
[self addSubview:navBar];
[navBar release];
UINavigationItem  *navItem = [[UINavigationItem alloc]initWithTitle:@"高分榜" ];
UIBarButtonItem  *barButtonItem =[[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleBordered target:self action:@selector(back)];
   navItem.leftBarButtonItem = barButtonItem;
navItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"删去" style: UIBarButtonItemStyleDone target:self action:@selector(delete)];
[navBar pushNavigationItem:navItem animated:NO];



设置时间


NSDate *currentDate = [NSDate date]; 
  NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
  [formatter setDateFormat:@"yyyy_MM_dd"]; [formatter setDateFormat:@"HH:mm:ss"]; 
 [formatter setAMSymbol:@"上午"]; 
 [formatter setPMSymbol:@"下午"]; 
 NSString *string = [formatter stringFromDate:currentDate]);



图片上传


//要完成UIImagePickerControllerDelegate 和UINavigationControllerDelegate


UIImagePickerController *myPicker = [[UIImagePickerController alloc] init];
myPicker.delegate = self;
switch ([sender tag]) {
//选择上传的类型
case 1:
//像册
if ([UIImagePickerController   isSourceTypeAvailable:  UIImagePickerControllerSourceTypePhotoLibrary]  ) 
{
myPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:myPicker animated:YES];
[myPicker release];
}
break;
//相机
case 2:
if ([UIImagePickerController isSourceTypeAvailable:  UIImagePickerControllerSourceTypeCamera]) 
{
myPicker.sourceType =   UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:myPicker animated:YES];
[myPicker release];
}
break;
case 3:
//胶卷
if ([UIImagePickerController isSourceTypeAvailable:  UIImagePickerControllerSourceTypeSavedPhotosAlbum]) 
{
myPicker.sourceType =   UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:myPicker animated:YES];
[myPicker release];
}
break;
default:
break;
}
}

#pragma mark-

#pragma mark UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
if (picker.sourceType = UIImagePickerControllerSourceTypeCamera ) 
{
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
[self dismissModalViewControllerAnimated:YES];
}
else {
_myImageView.frame = CGRectMake(120, 0, 75 * 2.5, 75 * 2.5);
_myImageView.image  = image;
[self.view addSubview:_myImageView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:_myImageView cache:YES];
_myImageView.frame = CGRectMake(0, 0, 50, 50);
[UIView commitAnimations] ;
[picker dismissModalViewControllerAnimated:YES];
}





用NSOperationQueue下载图片




参考http大讲堂的fromtable

//先在头文件中创建

 NSOperationQueue          *_queue;
 
NSMutableDictionary         *_dic;

//再在m文件中创建

_queue = [[NSOperationQueue alloc] init];
_dic = [[NSMutableDictionary alloc] init];

//放在一个循环中执行
    //占位图片
    UIImageView *imgView=(UIImageView *)[cell.contentView viewWithTag:5];
imgView.image=[UIImage imageNamed:@"a.png"];
NSString *currRow=[NSString stringWithFormat:@"%d",indexPath.row];
    
NSString *fullPath=[dict objectForKey:currRow];
    
if (fullPath) {//字典里当前行有图片就直接取值显示
UIImage *img=[UIImage imageWithContentsOfFile:fullPath];
imgView.image=img;
}
    else
    {//没有就下载
ImageLoader *imgLoader=[[ImageLoader alloc] initWithInfo:menu.imgPath view:cell.contentView dict:dict row:currRow];
[queue addOperation:imgLoader];
}
//创建一个ImageLoader的类并继承自NSOperation

并交给main方法执行 把下载图片的重任交给main方法执行,将相当于启动一个线程去执行下载



界面跳转方法



//弹到另一个界面的方法1
-(void)setCurrentViewController:(UIViewController *)newViewController{
if (_viewController != newViewController) 
{
if (_viewController) 
{
[_viewController.view removeFromSuperview];
[_viewController release];
}
_viewController = [newViewController retain];
[window addSubview:_viewController.view];
}
}
//弹到另一个界面的方法2

//setAnimationTransition 旋转方式
   UIViewAnimationTransitionNone,
    UIViewAnimationTransitionFlipFromLeft,
    UIViewAnimationTransitionFlipFromRight,
    UIViewAnimationTransitionCurlUp,
    UIViewAnimationTransitionCurlDown,

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
//[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:2];
[UIView commitAnimations];
//弹到另一个界面的方法3 导航 压榨入
[self.navigationController pushViewController:<#(UIViewController *)viewController#> animated:YES];

//压榨出 
[self.navigationController popViewControllerAnimated:YES ];

//弹到另一个界面的方法4 模态弹出

//弹出方式
self.modalTransitionStyle =  UIModalTransitionStyleCoverVertical = 0,
    UIModalTransitionStyleFlipHorizontal,
    UIModalTransitionStyleCrossDissolve,
    
[self presentModalViewController:<#(UIViewController *)modalViewController#> animated:YES];
[self dismissModalViewControllerAnimated:YES];


电影播放


//导入框架MediaPlayer

#import <MediaPlayer/MediaPlayer.h>


1MPMoviePlayerViewController *viewPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    
viewPlayer.moviePlayer.shouldAutoplay = YES;
    
[viewPlayer.moviePlayer setFullscreen:YES animated:YES];
[self presentModalViewController:viewPlayer animated:YES];
    
[viewPlayer shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];

2 MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:url];
if (mp)//如果不为空
{
self.moviePlayer = mp;
[mp release];
[self.moviePlayer play];//播放对象
//4.0专用
self.moviePlayer.view.frame = CGRectMake(155, 180, 160, 250);
[self.view addSubview:_moviePlayer.view];
}


运动学


计算一般按点的坐标来算。首先要判断点所在的象限,主要是通过  x2x1  0 的关系,

y2y1 0 的关系,来确定所在象限。 然后计算坐标的角度。来设置打击精确度和雪花运动的方向。

 

矩形碰撞问题

  

x1+w1>x2 &&x2+w2>x1

y2+h2>y1 && y1+h1>y2;

 



    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多