p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #8b84cf}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px 'Heiti SC Light'; color: #4cbf57}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #ffffff}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #4cbf57}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #ffffff; min-height: 21.0px}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #c2349b}p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #e44448}p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px 'Heiti SC Light'; color: #ffffff}p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #d28f5a}p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #4cbf57; min-height: 21.0px}p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px 'Heiti SC Light'; color: #d28f5a}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font: 18.0px Menlo; font-variant-ligatures: no-common-ligatures}span.s3 {font-variant-ligatures: no-common-ligatures; color: #8b84cf}span.s4 {font-variant-ligatures: no-common-ligatures; color: #ffffff}span.s5 {font-variant-ligatures: no-common-ligatures; color: #c2349b}span.s6 {font: 18.0px 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures}span.s7 {font-variant-ligatures: no-common-ligatures; color: #4cbf57}span.s8 {font: 18.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #8b84cf}span.s9 {font: 18.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #ffffff}span.s10 {font-variant-ligatures: no-common-ligatures; color: #e44448}span.s11 {font: 18.0px 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures; color: #ffffff}span.s12 {font: 18.0px 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures; color: #e44448}span.s13 {font-variant-ligatures: no-common-ligatures; color: #d28f5a}
// 延迟0.25秒就会调用里面代码块的东西
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// codeing...
});
//添加一个定时器
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(update) userInfo:nil repeats:YES];
//创建CADisplayLink (当每一屏幕刷新就会调用 每一秒刷新60)
CADisplayLink *link = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
[link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
- //setNeedsDisplay它会调用drawRect,它并不是立马,只是设了一个标志,当下一次屏幕刷新的调用.
[self setNeedsDisplay];
3.// UIGeometry.h
// UIKit
UIKIT_EXTERN const UIEdgeInsets UIEdgeInsetsZero;
UIKIT_EXTERN const UIOffset UIOffsetZero;
UIKIT_EXTERN NSString *NSStringFromCGPoint(CGPoint point);
UIKIT_EXTERN NSString *NSStringFromCGVector(CGVector vector);
UIKIT_EXTERN NSString *NSStringFromCGSize(CGSize size);
UIKIT_EXTERN NSString *NSStringFromCGRect(CGRect rect);
UIKIT_EXTERN NSString *NSStringFromCGAffineTransform(CGAffineTransform transform);
UIKIT_EXTERN NSString *NSStringFromUIEdgeInsets(UIEdgeInsets insets);
UIKIT_EXTERN NSString *NSStringFromUIOffset(UIOffset offset);
UIKIT_EXTERN CGPoint CGPointFromString(NSString *string);
UIKIT_EXTERN CGVector CGVectorFromString(NSString *string);
UIKIT_EXTERN CGSize CGSizeFromString(NSString *string);
UIKIT_EXTERN CGRect CGRectFromString(NSString *string);
UIKIT_EXTERN CGAffineTransform CGAffineTransformFromString(NSString *string);
UIKIT_EXTERN UIEdgeInsets UIEdgeInsetsFromString(NSString *string);
UIKIT_EXTERN UIOffset UIOffsetFromString(NSString *string);
@interface NSValue (NSValueUIGeometryExtensions)
- (NSValue *)valueWithCGPoint:(CGPoint)point;
- (NSValue *)valueWithCGVector:(CGVector)vector;
- (NSValue *)valueWithCGSize:(CGSize)size;
- (NSValue *)valueWithCGRect:(CGRect)rect;
- (NSValue *)valueWithCGAffineTransform:(CGAffineTransform)transform;
- (NSValue *)valueWithUIEdgeInsets:(UIEdgeInsets)insets;
- (NSValue *)valueWithUIOffset:(UIOffset)insets NS_AVAILABLE_IOS(5_0);
- (CGPoint)CGPointValue;
- (CGVector)CGVectorValue;
- (CGSize)CGSizeValue;
- (CGRect)CGRectValue;
- (CGAffineTransform)CGAffineTransformValue;
- (UIEdgeInsets)UIEdgeInsetsValue;
- (UIOffset)UIOffsetValue NS_AVAILABLE_IOS(5_0);
@end
4.// UIImage.h
// UIKit
UIKIT_EXTERN NSData *UIImagePNGRepresentation(UIImage *image); // return image as PNG. May return nil if image has no CGImageRef or invalid bitmap format
UIKIT_EXTERN NSData *UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality); // return image as JPEG. May return nil if image has no CGImageRef or invalid bitmap format. compression is 0(most)..1(least)
//如何把图片转换成二进流.
NSData *data = UIImagePNGRepresentation(newImage);
// UIImageJPEGRepresentation(<#UIImage *image#>, <#CGFloat compressionQuality#>)
[data writeToFile:@"/Users/gaoxinqiang/Desktop/newImage.png" atomically:YES];
5.设置父控件的hidden=yes,其子控件也会被隐藏
设置父控件的alpha<=0.01的时候,其子控件也会被影响 ,变得看不见
0.01的时候没事.
系统默认的UIView(用代码创建的UIView和拖出的都是,默认是clearcolor的background属性的,alpha>0.01)clearcolor的alpha>0.01,子控件不影响显示
理解:alpha>0.01透明但存在(不可穿透),alpha<=0.01类似不存在,皮之不存,毛之焉附(可以穿透).
系统默认的UIImageView是没有background属性的
6.如何开启一个图片上下文?
size:开启多大的上文
opaque:是否不透明//Yes的时候Context没有绘画内容的地方为黑色,No的时候为透明的
scale:缩放上下文.
UIGraphicsBeginImageContextWithOptions(image.size, YES, 0);
7.//判断一个点在不在某个区域当中
CGRectContainsPoint(btn.frame, point)
//-(BOOl)pointInSet...hitTest中调用
- transform:底层是通过找到需要形变对象的父类,调用父类的layoutSubviews,改变他的frame,bounds不会改变。因为frame能决定他在父控件显示的位置和尺寸。
也就是说控件进过transform之后,只是改变了它在父类中的显示的位置和尺寸,但是他的实际大小(bounds)不会改变.所以如果把它render到context中,和没有进行过transform的时候是一样的.绘图只和size有关(而我们在开启context的时候通常传入bounds.size作为context的size),还有绘图模式比如drawAtPoint照着内容原来大小绘如context,drawInCGRect,把内容缩放绘入context指定的Rect,还有一种平铺的
static NSArray *b;
b=[NSArray arrayWithObjects:@{@"s":@"v"},@"s",@[@"s_---"], nil];
//forin以NSString *类型去取出了所有对象
for (NSString *a in b) {
NSLog(@"%@",a);
}
2015-09-14 23:12:26.160 06-画板[3242:21948] {
s = v;
}
2015-09-14 23:12:26.161 06-画板[3242:21948] s
2015-09-14 23:12:26.161 06-画板[3242:21948] (
"s_---"
)
10.typedef struct CGContext * CGContextRef;
11.截图
从view.layer render去context,然后从context的到image(UIGraphicsGetImageFromCurrentImageContext();),再把image写入dir
//用函数(UIPickerConter.h)写入相册或者用函数(UIImage.h)转为NSData再写入dir
11-1//写到系统相册当中(Album相册)
//注意,保存成功调用的方法必须得是
//- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
UIImageWriteToSavedPhotosAlbum(newImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
11-2//如何把图片转换成二进流.//第4点tips
NSData *data = UIImagePNGRepresentation(newImage);
// UIImageJPEGRepresentation(<#UIImage *image#>, <#CGFloat compressionQuality#>)
[data writeToFile:@"/Users/gaoxinqiang/Desktop/newImage.png" atomically:YES];
12.modal
//completion(presentViewController后执行代码块)
[self presentViewController:temp animated:YES completion:nil];
self dismissViewControllerAnimated:<#(BOOL)#> completion:<#^(void)completion#>
13.CGAffineTransform结构体(view实例.transform)结合frame完美表现View在其父View或者屏幕上的样子,设置控件形变(平移,旋转,缩放,等等)
typedef struct CGAffineTransform CGAffineTransform;
struct CGAffineTransform {
CGFloat a, b, c, d;
CGFloat tx, ty;
};
//frame +transform.
平移Translation(Translate)
旋转Rotation
缩放Scale
// sx:宽度缩放比例, sy:高度缩放比例
颠倒Invert
14./**文档中找到的
* The concrete subclasses of UIGestureRecognizer are the following:
UITapGestureRecognizer//轻点,敲击
UIPinchGestureRecognizer//捏合,用于缩放
UIRotationGestureRecognizer//旋转
UISwipeGestureRecognizer//轻扫
UIPanGestureRecognizer//拖动
UIScreenEdgePanGestureRecognizer//
UILongPressGestureRecognizer//长按
*/
15.-(void)pinch:(UIPinchGestureRecognizer *)pinch
{
//sx,sy都是pinch.scale(手势捏合只有一个两指头间距从开始到结束比例,同一手势累计)
//只有一个值所以手势捏合缩放,等比例,或者有人设计只是缩放宽高的一个
pinch.view.transform=CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);
// 复位
pinch.scale = 1;
}
-(void)rotation:(UIRotationGestureRecognizer *)rotation
{
// 旋转图片
rotation.view.transform = CGAffineTransformRotate(rotation.view.transform, rotation.rotation);
// 复位,只要想相对于上一次旋转就复位
rotation.rotation = 0;
}
16.#warning ImageView默认是不能与用户交互的,改为能
self.imageV .userInteractionEnabled=YES;
17.-(void)layoutSubviews
{ [super layoutSubviews];
//在这里写了要进行形变的view的frame后,不能进行形变了,旋转可以但是左上角和右下角固定.
self.imageV.frame=self.bounds;
}
warning 记得UIGraphicsEndImageContext();
当自己的类(对象),需要别的类(对象)的数据,或者要改别的类属性时,或者因为事件发生需要使用别的类的方法的时候.在自己的类,设一个容器,存放别的类,就可以拿到别的类,实现目的,这时为了降低耦合,用代理容器,存别的类,用协议方法,实现数据交互.(非MVC中的相关类,父子对象控件父可以直接用对象容器,...)
20.@interface NSValue (CATransform3DAdditions)
- (NSValue *)valueWithCATransform3D:(CATransform3D)t;
@property(readonly) CATransform3D CATransform3DValue;
@end
- //在C语言当中用的都是像素,我们这个地方加载@2x
//加载原始图片
UIImage *oriImage = [UIImage imageNamed:@"LuckyAstrology"];
UIImage *oriSelImage = [UIImage imageNamed:@"LuckyAstrologyPressed"];
//获取当前屏幕与像素坐标的比例
//一个点.x拉伸多少像素.x
CGFloat scale = [UIScreen mainScreen].scale;
CGFloat clipW = oriImage.size.width / 12 * scale;
CGFloat clipH = oriImage.size.height * scale;
CGFloat clipX = 0;
CGFloat clipY = 0;
//CGimgae(CG...)是c语言中的兼容OS 和iOS ,像素作为基本单位,UIIamge(iOS手机专用,以点作为基本单位)
//裁剪图片当中的某一块区域
CGRect rect = CGRectMake(clipX, clipY, clipW, clipH);
CGImageRef clipImage = CGImageCreateWithImageInRect(oriImage.CGImage, rect);
//把CGImageRef转成UIImage
UIImage *clipNewImage = [UIImage imageWithCGImage:clipImage];
23.UIView的详细显示过程
当UIView需要显示时,它内部的层会准备好一个CGContextRef(图形上下文),然后调用delegate(这里就是UIView)的drawLayer:inContext:方法,并且传入已经准备好的CGContextRef对象。而UIView在drawLayer:inContext:方法中又会调用自己的drawRect:方法
平时在drawRect:中通过UIGraphicsGetCurrentContext()获取的就是由层传入的CGContextRef对象,在drawRect:中完成的所有绘图都会填入层的CGContextRef中,然后被拷贝至屏幕
24.//拿当选中按钮的旋转角度.
CGAffineTransform transform = self.preBtn.transform;
// t' = [ cos(angle) sin(angle) -sin(angle) cos(angle) 0 0 ]
//atan2f(math.h反三角函数,传入两个边获得弧度,tan(...) sin cos)
// CGFloat angel = atan2f(transform.b, transform.a);
CGFloat angel = acosf(transform.a);
NSLog(@"%lf",angel);
//让ContentV倒着旋转回去.
self.contentV.transform = CGAffineTransformMakeRotation(angel);
25.[self.superview insertSubview:smallCircle belowSubview:self];
26.模拟器和真机的尺寸由启动图片决定
27.//修改transform,并不会改center,底层改的是frame
28.给layer设置图片.
layer.contents = (id)[UIImage imageNamed:@"阿狸头像"].CGImage;
29.#translation:每次手指移动产生的移动向量的累加
//手势的translationInView:self==translationInView:self.superview,这里传的参数self.superview和传self是一样的
//translation底层计算translation+=手指(这次位置改变后)的在self的位置-手指(这次位置改变前)在self的位置(向量)(总的相当于,所有改变以前的手指在self的位置和这次改变后手指在self的位置的两点向量)(或者总的相当于,所有改变以前的手指在self.super的位置和这次改变后手指在self.super的位置的两点向量,所以两个是一样的)
CGPoint po=[pan translationInView:self];
CGPoint pi=[pan translationInView:self.superview];
NSLog(@"po=%@,pi=%@",NSStringFromCGPoint(po),NSStringFromCGPoint(pi));
30.
父子对象控件父可以直接用对象容器拿到subview,子控件需要改变父控件的属性时,可以在自己的属性中加一个模型属性,然后由父控件去取这个模型设置自己的内容,如系统的navagetianbarItem模型和tabbarItem模型都是父控件的bar设置的时候取出子控件Item属性模型,来设置..
//因事件发生而需要改变,别的类,或控件属性时,用代理,或者通知
31.// 插件路径:前往 -> 资源库 -> Application Support -> Developer
32.// 获取当前整个应用程序下的所有导航条的外观
// UINavigationBar *navBar = [UINavigationBar appearance];
// 只影响当前类下面的导航条
// 获取当前类下面的导航条
UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
33.#warning viewDidLoad的时候tableBar的子控件还没加载
34.UITableView的IndexPath对象
@interface NSIndexPath (UITableView)
- (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;
@property (nonatomic, readonly) NSInteger section;
@property (nonatomic, readonly) NSInteger row;
@end
35.// 导航控制器显示一个控制器完成的时候就会调用
-
(void)navigationController:(nonnull UINavigationController *)navigationController didShowViewController:(nonnull UIViewController *)viewController animated:(BOOL)animated
{
if (viewController == self.childViewControllers[0]) {
// 回到根控制器
self.interactivePopGestureRecognizer.delegate = _popDelegate;
}else{ // 不是根控制器
self.interactivePopGestureRecognizer.delegate = nil;}
}
36.typeof(什么都可)//返回传入东东的类型
int a;==typeof(a) a;