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秒就會(huì)調(diào)用里面代碼塊的東西
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// codeing...
});
//添加一個(gè)定時(shí)器
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(update) userInfo:nil repeats:YES];
//創(chuàng)建CADisplayLink (當(dāng)每一屏幕刷新就會(huì)調(diào)用 每一秒刷新60)
CADisplayLink *link = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
[link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
- //setNeedsDisplay它會(huì)調(diào)用drawRect,它并不是立馬,只是設(shè)了一個(gè)標(biāo)志,當(dāng)下一次屏幕刷新的調(diào)用.
[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)
//如何把圖片轉(zhuǎn)換成二進(jìn)流.
NSData *data = UIImagePNGRepresentation(newImage);
// UIImageJPEGRepresentation(<#UIImage *image#>, <#CGFloat compressionQuality#>)
[data writeToFile:@"/Users/gaoxinqiang/Desktop/newImage.png" atomically:YES];
5.設(shè)置父控件的hidden=yes,其子控件也會(huì)被隱藏
設(shè)置父控件的alpha<=0.01的時(shí)候,其子控件也會(huì)被影響 ,變得看不見(jiàn)
0.01的時(shí)候沒(méi)事.
系統(tǒng)默認(rèn)的UIView(用代碼創(chuàng)建的UIView和拖出的都是,默認(rèn)是clearcolor的background屬性的,alpha>0.01)clearcolor的alpha>0.01,子控件不影響顯示
理解:alpha>0.01透明但存在(不可穿透),alpha<=0.01類(lèi)似不存在,皮之不存,毛之焉附(可以穿透).
系統(tǒng)默認(rèn)的UIImageView是沒(méi)有background屬性的
6.如何開(kāi)啟一個(gè)圖片上下文?
size:開(kāi)啟多大的上文
opaque:是否不透明//Yes的時(shí)候Context沒(méi)有繪畫(huà)內(nèi)容的地方為黑色,No的時(shí)候?yàn)橥该鞯?br>
scale:縮放上下文.
UIGraphicsBeginImageContextWithOptions(image.size, YES, 0);
7.//判斷一個(gè)點(diǎn)在不在某個(gè)區(qū)域當(dāng)中
CGRectContainsPoint(btn.frame, point)
//-(BOOl)pointInSet...hitTest中調(diào)用
- transform:底層是通過(guò)找到需要形變對(duì)象的父類(lèi),調(diào)用父類(lèi)的layoutSubviews,改變他的frame嫌拣,bounds不會(huì)改變。因?yàn)閒rame能決定他在父控件顯示的位置和尺寸孝宗。
也就是說(shuō)控件進(jìn)過(guò)transform之后,只是改變了它在父類(lèi)中的顯示的位置和尺寸,但是他的實(shí)際大小(bounds)不會(huì)改變.所以如果把它render到context中,和沒(méi)有進(jìn)行過(guò)transform的時(shí)候是一樣的.繪圖只和size有關(guān)(而我們?cè)陂_(kāi)啟context的時(shí)候通常傳入bounds.size作為context的size),還有繪圖模式比如drawAtPoint照著內(nèi)容原來(lái)大小繪如context,drawInCGRect,把內(nèi)容縮放繪入context指定的Rect,還有一種平鋪的
static NSArray *b;
b=[NSArray arrayWithObjects:@{@"s":@"v"},@"s",@[@"s_---"], nil];
//forin以NSString *類(lèi)型去取出了所有對(duì)象
for (NSString *a in b) {
NSLog(@"%@",a);
}
2015-09-14 23:12:26.160 06-畫(huà)板[3242:21948] {
s = v;
}
2015-09-14 23:12:26.161 06-畫(huà)板[3242:21948] s
2015-09-14 23:12:26.161 06-畫(huà)板[3242:21948] (
"s_---"
)
10.typedef struct CGContext * CGContextRef;
11.截圖
從view.layer render去context,然后從context的到image(UIGraphicsGetImageFromCurrentImageContext();),再把image寫(xiě)入dir
//用函數(shù)(UIPickerConter.h)寫(xiě)入相冊(cè)或者用函數(shù)(UIImage.h)轉(zhuǎn)為NSData再寫(xiě)入dir
11-1//寫(xiě)到系統(tǒng)相冊(cè)當(dāng)中(Album相冊(cè))
//注意,保存成功調(diào)用的方法必須得是
//- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
UIImageWriteToSavedPhotosAlbum(newImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
11-2//如何把圖片轉(zhuǎn)換成二進(jìn)流.//第4點(diǎn)tips
NSData *data = UIImagePNGRepresentation(newImage);
// UIImageJPEGRepresentation(<#UIImage *image#>, <#CGFloat compressionQuality#>)
[data writeToFile:@"/Users/gaoxinqiang/Desktop/newImage.png" atomically:YES];
12.modal
//completion(presentViewController后執(zhí)行代碼塊)
[self presentViewController:temp animated:YES completion:nil];
self dismissViewControllerAnimated:<#(BOOL)#> completion:<#^(void)completion#>
13.CGAffineTransform結(jié)構(gòu)體(view實(shí)例.transform)結(jié)合frame完美表現(xiàn)View在其父View或者屏幕上的樣子,設(shè)置控件形變(平移,旋轉(zhuǎn),縮放,等等)
typedef struct CGAffineTransform CGAffineTransform;
struct CGAffineTransform {
CGFloat a, b, c, d;
CGFloat tx, ty;
};
//frame +transform.
平移Translation(Translate)
旋轉(zhuǎn)Rotation
縮放Scale
// sx:寬度縮放比例, sy:高度縮放比例
顛倒Invert
14./**文檔中找到的
* The concrete subclasses of UIGestureRecognizer are the following:
UITapGestureRecognizer//輕點(diǎn),敲擊
UIPinchGestureRecognizer//捏合,用于縮放
UIRotationGestureRecognizer//旋轉(zhuǎn)
UISwipeGestureRecognizer//輕掃
UIPanGestureRecognizer//拖動(dòng)
UIScreenEdgePanGestureRecognizer//
UILongPressGestureRecognizer//長(zhǎng)按
*/
15.-(void)pinch:(UIPinchGestureRecognizer *)pinch
{
//sx,sy都是pinch.scale(手勢(shì)捏合只有一個(gè)兩指頭間距從開(kāi)始到結(jié)束比例,同一手勢(shì)累計(jì))
//只有一個(gè)值所以手勢(shì)捏合縮放,等比例,或者有人設(shè)計(jì)只是縮放寬高的一個(gè)
pinch.view.transform=CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);
// 復(fù)位
pinch.scale = 1;
}
-(void)rotation:(UIRotationGestureRecognizer *)rotation
{
// 旋轉(zhuǎn)圖片
rotation.view.transform = CGAffineTransformRotate(rotation.view.transform, rotation.rotation);
// 復(fù)位,只要想相對(duì)于上一次旋轉(zhuǎn)就復(fù)位
rotation.rotation = 0;
}
16.#warning ImageView默認(rèn)是不能與用戶(hù)交互的,改為能
self.imageV .userInteractionEnabled=YES;
17.-(void)layoutSubviews
{ [super layoutSubviews];
//在這里寫(xiě)了要進(jìn)行形變的view的frame后,不能進(jìn)行形變了,旋轉(zhuǎn)可以但是左上角和右下角固定.
self.imageV.frame=self.bounds;
}
warning 記得UIGraphicsEndImageContext();
當(dāng)自己的類(lèi)(對(duì)象),需要?jiǎng)e的類(lèi)(對(duì)象)的數(shù)據(jù),或者要改別的類(lèi)屬性時(shí),或者因?yàn)槭录l(fā)生需要使用別的類(lèi)的方法的時(shí)候.在自己的類(lèi),設(shè)一個(gè)容器,存放別的類(lèi),就可以拿到別的類(lèi),實(shí)現(xiàn)目的,這時(shí)為了降低耦合,用代理容器,存別的類(lèi),用協(xié)議方法,實(shí)現(xiàn)數(shù)據(jù)交互.(非MVC中的相關(guān)類(lèi),父子對(duì)象控件父可以直接用對(duì)象容器,...)
20.@interface NSValue (CATransform3DAdditions)
- (NSValue *)valueWithCATransform3D:(CATransform3D)t;
@property(readonly) CATransform3D CATransform3DValue;
@end
- //在C語(yǔ)言當(dāng)中用的都是像素,我們這個(gè)地方加載@2x
//加載原始圖片
UIImage *oriImage = [UIImage imageNamed:@"LuckyAstrology"];
UIImage *oriSelImage = [UIImage imageNamed:@"LuckyAstrologyPressed"];
//獲取當(dāng)前屏幕與像素坐標(biāo)的比例
//一個(gè)點(diǎn).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語(yǔ)言中的兼容OS 和iOS ,像素作為基本單位,UIIamge(iOS手機(jī)專(zhuān)用,以點(diǎn)作為基本單位)
//裁剪圖片當(dāng)中的某一塊區(qū)域
CGRect rect = CGRectMake(clipX, clipY, clipW, clipH);
CGImageRef clipImage = CGImageCreateWithImageInRect(oriImage.CGImage, rect);
//把CGImageRef轉(zhuǎn)成UIImage
UIImage *clipNewImage = [UIImage imageWithCGImage:clipImage];
23.UIView的詳細(xì)顯示過(guò)程
當(dāng)UIView需要顯示時(shí),它內(nèi)部的層會(huì)準(zhǔn)備好一個(gè)CGContextRef(圖形上下文)耕肩,然后調(diào)用delegate(這里就是UIView)的drawLayer:inContext:方法因妇,并且傳入已經(jīng)準(zhǔn)備好的CGContextRef對(duì)象。而UIView在drawLayer:inContext:方法中又會(huì)調(diào)用自己的drawRect:方法
平時(shí)在drawRect:中通過(guò)UIGraphicsGetCurrentContext()獲取的就是由層傳入的CGContextRef對(duì)象猿诸,在drawRect:中完成的所有繪圖都會(huì)填入層的CGContextRef中婚被,然后被拷貝至屏幕
24.//拿當(dāng)選中按鈕的旋轉(zhuǎn)角度.
CGAffineTransform transform = self.preBtn.transform;
// t' = [ cos(angle) sin(angle) -sin(angle) cos(angle) 0 0 ]
//atan2f(math.h反三角函數(shù),傳入兩個(gè)邊獲得弧度,tan(...) sin cos)
// CGFloat angel = atan2f(transform.b, transform.a);
CGFloat angel = acosf(transform.a);
NSLog(@"%lf",angel);
//讓ContentV倒著旋轉(zhuǎn)回去.
self.contentV.transform = CGAffineTransformMakeRotation(angel);
25.[self.superview insertSubview:smallCircle belowSubview:self];
26.模擬器和真機(jī)的尺寸由啟動(dòng)圖片決定
27.//修改transform,并不會(huì)改center,底層改的是frame
28.給layer設(shè)置圖片.
layer.contents = (id)[UIImage imageNamed:@"阿貍頭像"].CGImage;
29.#translation:每次手指移動(dòng)產(chǎn)生的移動(dòng)向量的累加
//手勢(shì)的translationInView:self==translationInView:self.superview,這里傳的參數(shù)self.superview和傳self是一樣的
//translation底層計(jì)算translation+=手指(這次位置改變后)的在self的位置-手指(這次位置改變前)在self的位置(向量)(總的相當(dāng)于,所有改變以前的手指在self的位置和這次改變后手指在self的位置的兩點(diǎn)向量)(或者總的相當(dāng)于,所有改變以前的手指在self.super的位置和這次改變后手指在self.super的位置的兩點(diǎn)向量,所以?xún)蓚€(gè)是一樣的)
CGPoint po=[pan translationInView:self];
CGPoint pi=[pan translationInView:self.superview];
NSLog(@"po=%@,pi=%@",NSStringFromCGPoint(po),NSStringFromCGPoint(pi));
30.
父子對(duì)象控件父可以直接用對(duì)象容器拿到subview,子控件需要改變父控件的屬性時(shí),可以在自己的屬性中加一個(gè)模型屬性,然后由父控件去取這個(gè)模型設(shè)置自己的內(nèi)容,如系統(tǒng)的navagetianbarItem模型和tabbarItem模型都是父控件的bar設(shè)置的時(shí)候取出子控件Item屬性模型,來(lái)設(shè)置..
//因事件發(fā)生而需要改變,別的類(lèi),或控件屬性時(shí),用代理,或者通知
31.// 插件路徑:前往 -> 資源庫(kù) -> Application Support -> Developer
32.// 獲取當(dāng)前整個(gè)應(yīng)用程序下的所有導(dǎo)航條的外觀
// UINavigationBar *navBar = [UINavigationBar appearance];
// 只影響當(dāng)前類(lèi)下面的導(dǎo)航條
// 獲取當(dāng)前類(lèi)下面的導(dǎo)航條
UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
33.#warning viewDidLoad的時(shí)候tableBar的子控件還沒(méi)加載
34.UITableView的IndexPath對(duì)象
@interface NSIndexPath (UITableView)
- (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;
@property (nonatomic, readonly) NSInteger section;
@property (nonatomic, readonly) NSInteger row;
@end
35.// 導(dǎo)航控制器顯示一個(gè)控制器完成的時(shí)候就會(huì)調(diào)用
-
(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(什么都可)//返回傳入東東的類(lèi)型
int a;==typeof(a) a;