自定义字体时设置字体大小时不能在.号后加任何
多用继承/分类/扩展。不仅仅是对于UIViewcontroller 还有对于一些控件, 这对于整体的架构,以及后期的维护很重要。但是写继承的时候要注意分块儿,不然随着代码的迭代继承会成为你的累赘
继承/多态/封装。越看越重要
都能够让代码解耦、模块化,清晰起来 ,对于书写代码的思路也有很好的提升。
所以一开始拿到需求的时候,要先对整体有一个总的思路(框架),不仅仅是Nav/Tab 还有对于一些控件/UIView。webview内设置属性可以用js代码(h5),可以让webView看起来很酷
字典可以是多个数组的集合,字典取value指以及数组取value值十分重要
滑动控制器的contentSize
scrollView.contentSize = CGSizeMake(self.view.frame.size.width,CGRectGetMaxY(view.lastLabel.frame)+ 40);
或者可以用布局写scrollView距底为0
- 弹框动画
-(void)animationAlert:(UIView *)view{
CAKeyframeAnimation *popAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
popAnimation.duration = 0.4;
popAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.01f, 0.01f, 1.0f)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1f, 1.1f, 1.0f)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9f, 0.9f, 1.0f)],
[NSValue valueWithCATransform3D:CATransform3DIdentity]];
popAnimation.keyTimes = @[@0.0f, @0.5f, @0.75f, @1.0f];
popAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[view.layer addAnimation:popAnimation forKey:nil];
}
- 把数据源绑定到UIButton上
1、可以通过自定义Btn(继承),在此上新增属性作为参数
1
//写一个wxzBtn继承自UIButton,为了可以重写数据。因为UIBtton本身不能
@interface wxzBtn : UIButton
//Btn所绑定的东西
@property (nonatomic,strong) NSString * titlestring;
@end
@interface Mycell : UITableViewCell
@property (nonatomic,strong) wxzBtn * confirmBtn;
@end
2
在创建 confirmBtn按钮时是根据类wxzBtn创建
self.confirmBtn = [[wxzBtn alloc] init];
3
在按钮点击之前重写titlestring的值
cell.confirmBtn.titlestring = @"1111";
[cell.confirmBtn addTarget:self action:@selector(confirmBtnClick:) forControlEvents:UIControlEventTouchUpInside];
4
- (void)confirmBtnClick:(wxzBtn *)btn{
NSLog(@"%@",btn.titlestring);
}
- 知道返回数据的Json格式特别重要,因为在tableview等一些控制器里有section和row 这里需要对解析格式特别熟练 比如数组A里有一个字典---字典里有字符串,数组B---数组B里又有字符串
- 加载本地的gif图片
- (void)viewDidLoad {
[super viewDidLoad];
_imageIV = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
[self.view addSubview:_imageIV];
_imageIV.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"party_sel_00000" ofType:@"png"]];
_imageIV.backgroundColor = [UIColor redColor];
[self configMainImageView];
}
- (void)configMainImageView {
self.imageIV.animationImages = [self initialImageArray];
self.imageIV.animationDuration = 3.f;
self.imageIV.animationRepeatCount = 1;
[self.imageIV startAnimating];
[self performSelector:@selector(clearAinimationImageMemory) withObject:nil afterDelay:3.0f];
}
- (NSArray *)initialImageArray {
NSMutableArray *imageArray = [[NSMutableArray alloc] init];
for (int i = 0; i < 26; i++) {
NSString * imageName ;
if (i >= 10) {
imageName = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"party_sel_000%d@2x",i]ofType:@"png"];
}else{
imageName = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"party_sel_0000%d@2x",i]ofType:@"png"];
}
UIImage *image = [UIImage imageWithContentsOfFile:imageName];
[imageArray addObject:image];
}
return imageArray;
}
- (void)clearAinimationImageMemory {
[self.imageIV stopAnimating];
self.imageIV.animationImages = nil;
}
self.userInteractionEnabled = NO;
设置了当前self不能和用户交互,相当于显示了一张图片VIew里的跳转
1、获取当前界面(VC)的Nav 然后Push
2、获取当前窗口的可见控制器Pushbtn的img和title的内边距设置
在设置内边距的时候直接设置img和title的位置就可以了。销毁某个View时
正确的做法
1、[view removeFromSuperview ];
2、view = nil;
原因如下:
_View = nil;
[_View removeFromSuperview];
//理解内存管理, 一个变量的何时销毁。
//_View 在视图上的时候是有两个引用,一个父视图,一个——_View变量,先把——_View设置nil,就不能执行这句话了
[nil removeFromSuperview];
KVC真的很好用! 不管是在什么情况下都可以取到某些特定的值
利用贝塞尔曲线切view的边角
//创建
UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 200, 70)];
myLabel.text = @"Hello,world";
myLabel.font = [UIFont systemFontOfSize:20.0];
myLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:myLabel];
CGFloat radius = 21.0f;
//利用贝塞尔曲线为label的边距设置
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:myLabel.bounds byRoundingCorners:UIRectCornerTopRight|UIRectCornerBottomRight|UIRectCornerTopLeft cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer * mask = [[CAShapeLayer alloc] init];
mask.lineWidth = 5;
// kCGLineCapButt:无端点
kCGLineCapRound:圆形端点
kCGLineCapSquare:方形端点(样式上和kCGLineCapButt是一样的,但是比kCGLineCapButt长一点)
//
mask.lineCap = kCALineCapSquare;
// 带边框则两个颜色不要设置成一样即可
mask.strokeColor = [UIColor redColor].CGColor;
mask.fillColor = [UIColor yellowColor].CGColor;
mask.path = path.CGPath;
[myLabel.layer addSublayer:mask];
- 加载帧动画
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImageView *animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 77/2, 118/2)];
animatedImageView.image = [UIImage imageNamed:@"personaldata_reward"];
//图片控件添加到视图上面去
[self.view addSubview:animatedImageView];
//创建一个可变数组
NSMutableArray *animationImages=[NSMutableArray array];
for(int I=1;I<=12;I++){
//通过for 循环,把我所有的 图片存到数组里面
NSString *imageName=[NSString stringWithFormat:@"personaldata_reward%d",I];
UIImage *image=[UIImage imageNamed:imageName];
[animationImages addObject:image];
}
// 设置图片的序列帧 图片数组
animatedImageView.animationImages=ary;
//动画重复次数 0代表无限选婚
animatedImageView.animationRepeatCount=1;
//动画执行时间,多长时间执行完动画
animatedImageView.animationDuration=3.0;
//开始动画
if (! animatedImageView.isAnimating) {
[animatedImageView startAnimating];
}
//添加一个按钮,把帧动画添加到按钮里
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(HCSystemWidth-50, HCSystemHeight/2+HCScaleHeight(100), 77/2, 118/2)];
[btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
[btn addSubview:animatedImageView];
[btn bringSubviewToFront:animatedImageView];
[self.view addSubview:btn];
}
离开界面的时候的
[animatedImageView stopAnimating];