Fork me on GitHub

2012年3月6日

摘要: 类似于一个网络状况的探针。 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil]; hostReach = [[Reachability reachabilityWithHostName: @"hubj.cnblogs.com"] retain]; [hostReach startNotifier]; wifiReach=[[Rea 阅读全文
posted @ 2012-03-06 16:56 pengyingh 阅读(13443) 评论(0) 推荐(0)
摘要: 感谢大家关注,自己找到问题的原因了。虚拟器不支持按下"Home"后继续播放,真机Ok!在按下设备的 “home”键后,程序在后台运行,希望继续播放乐曲。各位老大帮看看我哪里做错了?或缺少什么代码?谢谢。我已经进行了如下设置:在程序启动时- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Override point for customization after application launch./ 阅读全文
posted @ 2012-03-06 16:41 pengyingh 阅读(459) 评论(0) 推荐(0)
摘要: CGRect frame = CGRectMake (origin.x, origin.y, size.width, size.height);矩形NSStringFromCGRect(someCG) 把CGRect结构转变为格式化字符串;CGRectFromString(aString) 由字符串恢复出矩形;CGRectInset(aRect) 创建较小或较大的矩形(中心点相同),+较小 -较大CGRectIntersectsRect(rect1, rect2) 判断两矩形是否交叉,是否重叠CGRectZero 高度和宽度为零的/位于(0,0)的矩形常量 阅读全文
posted @ 2012-03-06 16:23 pengyingh 阅读(146) 评论(0) 推荐(0)
摘要: 加载到NSArray/NSMutableArray里的对象,不需要负责releaseThe objects added to NSArray/NSMutableArray need not to be released.copy是创建,retain是引用the copy operation is create a new one,but the retain operation is just a reference.you触摸的不是UIEvent,而是NSSet的UIViewwhat you touch on screen is not UIEvent but UIView屏幕上看到的,都是 阅读全文
posted @ 2012-03-06 16:03 pengyingh 阅读(3433) 评论(0) 推荐(0)
摘要: 做过几次有关UIView坐标变换的,但是经常不能得到自己想要的效果,今天就把它仔细研究了下。记下来等以后忘记的时候再复习重写shouldAutorateToInterfaceOrientation:,限制某个方向会改变原点的位置,原点会一直保持在左上角,但已经不是原来的左上角了setStatusBarOrientation.改变状态栏的方向。它不会改变原点的位置,但会改变键盘的方向旋转前self.myview的frame ={0,0,320,50}CGAffineTransform at =CGAffineTransformMakeRotation(M_PI/2);[self.myviewse 阅读全文
posted @ 2012-03-06 16:00 pengyingh 阅读(9570) 评论(0) 推荐(0)
摘要: 什么对象是dipatching的UIViewController旋转的方法调用,即负责:- shouldAutorotateToInterfaceOrientation:- willRotateToInterfaceOrientation:时间:- willAnimateFirstHalfOfRotationToInterfaceOrientation:时间:- willAnimateSecondHalfOfRotationFromInterfaceOrientation:时间:- didRotateFromInterfaceOrientation:我猜想,UIApplication(但也许是 阅读全文
posted @ 2012-03-06 15:54 pengyingh 阅读(1937) 评论(0) 推荐(0)
摘要: iOS的控件基类是UIView,要自定义,需要重写:- (id)initWithFrame: (CGRect) frame //依照Frame建立新的View,建立出來的View要通过addSubview加入到父View中。-(void)drawRect:(CGRect)rect //自画,永远不要直接调用drawRect,而要通过 [self setNeedDisplay],由系统再去异步调用drawRect。并且必须在主线程中调用。自定义UIView不能使用nib文件设计界面,必须在程序中用代码创建各个控件,否则即使在主线程中调用setNeedDisplay也是不起作用。 阅读全文
posted @ 2012-03-06 15:53 pengyingh 阅读(307) 评论(0) 推荐(0)
摘要: - (void)downloadAndParse:(NSURL *)url { self.downloadAndParsePool = [[NSAutoreleasePool alloc] init]; done = NO; self.parseFormatter = [[[NSDateFormatter alloc] init] autorelease]; [parseFormatter setDateStyle:NSDateFormatterLongStyle]; [parseFormatter setTimeStyle:NSDateFormatterNoSt... 阅读全文
posted @ 2012-03-06 15:35 pengyingh 阅读(220) 评论(0) 推荐(0)
摘要: 前言初学objectice-C的朋友都有一个困惑,总觉得对objective-C的内存管理机制琢磨不透,程序经常内存泄漏或莫名其妙的崩溃。我在这里总结了自己对objective-C内存管理机制的研究成果和经验,写了这么一个由浅入深的教程。希望对大家有所帮助,也欢迎大家一起探讨。此文涉及的内存管理是针对于继承于NSObject的Class。一 基本原理Objective-C的内存管理机制与.Net/Java那种全自动的垃圾回收机制是不同的,它本质上还是C语言中的手动管理方式,只不过稍微加了一些自动方法。1 Objective-C的对象生成于堆之上,生成之后,需要一个指针来指向它。ClassA * 阅读全文
posted @ 2012-03-06 15:14 pengyingh 阅读(276) 评论(0) 推荐(0)
摘要: 需要创建一个UIView, 把touch event写在此UIView里, 然后在controller里创建此UIView@interface YourCustomView : UIView@implementation YourCustomView// Override this function to get the touch- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"TOUCH!");}@interface YourViewController : UIViewC 阅读全文
posted @ 2012-03-06 15:06 pengyingh 阅读(526) 评论(0) 推荐(0)
摘要: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint locationInView = [touch locationInView:self]; CGPoint locationInSuperview = [touch locationInView:self.superview]; self.layer.anchorPoint = CGPointMake(locationInView.x / self... 阅读全文
posted @ 2012-03-06 15:01 pengyingh 阅读(408) 评论(0) 推荐(0)
摘要: 转自:http://www.cocoadev.com/index.pl?DoublyLinkedListThe following is the actual Objective C class that implements a doubly-linked list (a variation ofLinkedList). It can do the following:Addition of new elements to the front of the listForward traversal using internal iteratorBackward traversalRemov 阅读全文
posted @ 2012-03-06 14:58 pengyingh 阅读(245) 评论(0) 推荐(0)
摘要: - 自带颜色[selfsetBackgroundColor:[UIColorlightGrayColor]];- 自己设定颜色// R: 128 G: 90 B: 200UIColor*myColor = [UIColorcolorWithRed:(128.0/255.0)green:(90.0/255.0)blue:(200.0/255.0)alpha:1];- 自己设定背景图self.view.backgroundColor= [[UIColoralloc]initWithPatternImage:[UIImageimageNamed:@"whiteBackground.png& 阅读全文
posted @ 2012-03-06 14:57 pengyingh 阅读(121) 评论(0) 推荐(0)
摘要: 如果你是 Objective-C / Cocoa Touch 的重度使用者,那么你一定被一个东西困扰过:不同的 View Controller 之间,如果互相进行沟通?举个常见的例子。假设我们手头上有一个 UIViewController 实例,名叫 parentViewController ,在这个 parentViewController 生命周期的某个节点,它需要以 modal view controller 的形式 present 一个 UIViewController 实例。这个将要被 present 的 UIViewController 实例名叫 childViewControll 阅读全文
posted @ 2012-03-06 14:56 pengyingh 阅读(1408) 评论(0) 推荐(0)
摘要: 转自:http://www.codeios.com/thread-894-1-1.html这个很有用的 UIImage 扩展之前的帖子:UIImage得一个Category, Resizes(调整尺寸),支持放大和旋转,可在许多 App 中使用。代码:// // UIImage-Extensions.h // // Created by Hardy Macia on 7/1/09. // Copyright 2009 Catamount Software. All rights reserved. // #import <Foundation/Foun... 阅读全文
posted @ 2012-03-06 14:43 pengyingh 阅读(351) 评论(0) 推荐(0)
摘要: 在UIImage上加个1像素宽的透明边框UIImage*image = [UIImageimageNamed:@"cardBackDown.png"];CGRectimageRect =CGRectMake(0,0, image.size.width, image.size.height);UIGraphicsBeginImageContext(imageRect.size);[imagedrawInRect:CGRectMake(1,1,image.size.width-2,image.size.height-2)];image =UIGraphicsGetImageFr 阅读全文
posted @ 2012-03-06 14:43 pengyingh 阅读(600) 评论(0) 推荐(0)
摘要: 前一阵子读到一篇介绍CALayer(这里简单地称其为层)的教程,比较简单易懂,适合初学者,我在这里就不完全翻译了,只是把要点说明一下。请注意,我创建的UILable始终随着UIView的根CALayer的缩放而改变位置。)其次,CALayer的可以影响其外观的特性有:层的大小尺寸背景色内容(比如图像或是使用Core Graphics绘制的内容)是否使用圆角是否使用阴影等等需要说明的是CALayer的大部分属性都可以用来实现动画效果。另外,你可以直接使用CALayer,也可以使用其子类,如CAGradientLayer,CATextLayer, CAShapeLayer等等。首先要说的是CALa 阅读全文
posted @ 2012-03-06 14:30 pengyingh 阅读(407) 评论(0) 推荐(0)
摘要: 在tabBar区域加个视图CGRect frame = CGRectMake(0,0,320,48); UIView *v = [[UIView alloc]initWithFrame:frame]; [v setBackgroundColor:[[UIColor allor]initWithRed:70.0/255.0 green:65.0/255.0 blue:62.0/255.0 alpha:1.0]]; [rootController.tabBar insertSubview:v atIndex:0]; [v release];注意:addSubview是将view添加到... 阅读全文
posted @ 2012-03-06 13:37 pengyingh 阅读(4587) 评论(0) 推荐(0)
摘要: 状态条Status Bar[UIApplication sharedApplication].statusBarHidden = YES;或者// iOS3.2+支持[application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];statusBarHidden属性支持在iOS2.0+,setStatusBarHidden:animated:方法在iOS3.2中开始取消了,而采用了setStatusBarHidden:withAnimation:方法。上述方法只能实现在程序跳过loading(即启动画面)的时候 阅读全文
posted @ 2012-03-06 13:29 pengyingh 阅读(4228) 评论(0) 推荐(0)
摘要: 继承UIImageView,重写init函数。//旋转手势 UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer allor]initWithTarget:selft action:@selector(rotatePiece:)]; [self addGestureRecognizer:rotationGesture]; [rotationGesture release]; //放大缩小手势 UIPinchGestureRecognizer *pinchGesture = [[UIPinchG. 阅读全文
posted @ 2012-03-06 13:22 pengyingh 阅读(1481) 评论(0) 推荐(0)

导航