随记(一)

1.视图位置

//将一个UIView显示在最前面只需要调用其父视图的 
bringSubviewToFront()

//将一个UIView层推送到背后只需要调用其父视图
sendSubviewToBack()

//插入到某一层
[self.view insertSubview:toolBar aboveSubview:self.tableView];

2 单例传值

//存值
 NSUserDefaults * user = [NSUserDefaults standardUserDefaults];   
[user setObject:selStr forKey:@"selStr”];
[user synchronize];

//取值
NSUserDefaults *defau = [NSUserDefaults standardUserDefaults];       
 [rightTextArray replaceObjectAtIndex:selIndex withObject:[defau objectForKey:@"selStr"]];

//滚动tableView到指定节section
[myTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:button.tag] atScrollPosition:UITableViewScrollPositionTop animated:YES];

3 图片边框阴影

//阴影层:
    CALayer *layer = [_titleImage layer];
    layer.shadowOffset = CGSizeMake(0, 2);
    layer.shadowRadius = 3.0;
    layer.shadowColor = [UIColor blackColor].CGColor;
    layer.shadowOpacity = 0.5;

4 cell入场动画

 CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
 cell.layer.anchorPoint = CGPointMake(.5,.5);
 animation.fromValue = @0.0f;
 animation.toValue = @1.0f;
 animation.duration=1;
//  animation.autoreverses=YES;//是否反转变为原来的属性值
 //把animation添加到图层的layer中,便可以播放动画了。forKey指定要应用此动画的属性
 [cell.layer addAnimation:animation forKey:@"scale"];

5 视图旋转动画
链接:http://zhangmingwei.iteye.com/blog/2101782

//旋转动画。

[self.view.layer addAnimation:[self rotation:1 degree:180 direction:0 repeatCount:MAXFLOAT] forKey:nil];

-(CABasicAnimation *)rotation:(float)dur degree:(float)degree direction:(int)direction repeatCount:(int)repeatCount
{
    CATransform3D rotationTransform = CATransform3DMakeRotation(degree, 0, 1, direction);
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
    animation.toValue = [NSValue valueWithCATransform3D:rotationTransform];
    animation.duration  =  dur;
    animation.autoreverses = NO;
    animation.cumulative = NO;
    animation.fillMode = kCAFillModeForwards;
    animation.repeatCount = repeatCount;
    animation.delegate = self;
    return animation;
}

6 计算文本高度

  CGSize constraint = CGSizeMake(self.frame.size.width, 20000);

CGSize size = [@"哈哈哈哈哈哈哈哈" boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]}context:nil].size;

7 cell刷新

//一个section刷新    
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];    
[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];    
//一个cell刷新    
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];    
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];

8 去掉UItableview headerview黏性(sticky)

//去掉UItableview headerview黏性(sticky) UITableViewStylePlain
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == groupTableView)
    {
        CGFloat sectionHeaderHeight = 50; //sectionHeaderHeight
        if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);

        } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        }
    }
}

9 摇一摇


#pragma mark - 生命周期函数  
- (void)viewDidLoad {  
    [super viewDidLoad];  

    // 设置允许摇一摇功能  
    [UIApplication sharedApplication].applicationSupportsShakeToEdit = YES;  
    // 并让自己成为第一响应者  
    [self becomeFirstResponder];  

    return;  
}  

#pragma mark - 摇一摇相关方法  
// 摇一摇开始摇动  
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {  
    NSLog(@"开始摇动");  
    return;  
}  

// 摇一摇取消摇动  
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {  
    NSLog(@"取消摇动");  
    return;  
}  

// 摇一摇摇动结束  
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {  
    if (event.subtype == UIEventSubtypeMotionShake) { // 判断是否是摇动结束  
        NSLog(@"摇动结束");  
    }  
    return;  
} 

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值