10个非常实用的iOS小技巧

2020-01-18 21:44:57于海丽


DetailViewController *detailVC = [[DetailViewController alloc]init]; 
  //UIModalTransitionStyleFlipHorizontal 翻转 
  //UIModalTransitionStyleCoverVertical 底部滑出 
  //UIModalTransitionStyleCrossDissolve 渐显 
  //UIModalTransitionStylePartialCurl 翻页 
  detailVC.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
 
  [self presentViewController:detailVC animated:YES completion:nil]; 

8、图片处理只拿到图片的一部分


UIImage *image = [UIImage imageNamed:filename]; 
CGImageRef imageRef = image.CGImage; 
CGRect rect = CGRectMake(origin.x, origin.y ,size.width, size.height); 
//这里的宽高是相对于图片的真实大小 
 
//比如你的图片是400x400的那么(0,0,400,400)就是图片的全尺寸,想取哪一部分就设置相应坐标即可 
 
CGImageRef imageRefRect = CGImageCreateWithImageInRect(imageRef, rect); 
 
UIImage *imageRect = [[UIImage alloc] initWithCGImage:imageRefRect]; 

9、给UIView设置图片


UIImage *image = [UIImage imageNamed:@"playing"]; 
  _layerView.layer.contents = (__bridge id)image.CGImage; 
_layerView.layer.contentsCenter = CGRectMake(0.25, 0.25, 0.5, 0.5); 
//同样可以设置显示的图片范围 
//不过此处略有不同,这里的四个值均为0-1之间;对应的依然是写x,y,widt,height 

10、给TableView或者CollectionView的cell添加简单动画

只要在willDisplayCell方法中对将要显示的cell做动画即可:


- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath{ 

  NSArray *array = tableView.indexPathsForVisibleRows; 
 
  NSIndexPath *firstIndexPath = array[0]; 
  //设置anchorPoint 

  cell.layer.anchorPoint = CGPointMake(0, 0.5); 
   //为了防止cell视图移动,重新把cell放回原来的位置 
  cell.layer.position = CGPointMake(0, cell.layer.position.y);  
 
  //设置cell 按照z轴旋转90度,注意是弧度 
  if (firstIndexPath.row < indexPath.row) { 
       cell.layer.transform = CATransform3DMakeRotation(M_PI_2, 0, 0, 1.0); 
 
  }else{ 
 
    cell.layer.transform = CATransform3DMakeRotation(- M_PI_2, 0, 0, 1.0); 
 
  }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持ASPKU。


注:相关教程知识阅读请移步到IOS开发频道。