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 阅读(13445) 评论(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 阅读(463) 评论(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 阅读(148) 评论(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 阅读(3434) 评论(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 阅读(9572) 评论(0) 推荐(0)
摘要: 什么对象是dipatching的UIViewController旋转的方法调用,即负责:- shouldAutorotateToInterfaceOrientation:- willRotateToInterfaceOrientation:时间:- willAnimateFirstHalfOfRotationToInterfaceOrientation:时间:- willAnimateSecondHalfOfRotationFromInterfaceOrientation:时间:- didRotateFromInterfaceOrientation:我猜想,UIApplication(但也许是 阅读全文
posted @ 2012-03-06 15:54 pengyingh 阅读(1938) 评论(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 阅读(308) 评论(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 阅读(280) 评论(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 阅读(529) 评论(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 阅读(412) 评论(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 阅读(1409) 评论(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 阅读(352) 评论(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 阅读(602) 评论(0) 推荐(0)
摘要: 前一阵子读到一篇介绍CALayer(这里简单地称其为层)的教程,比较简单易懂,适合初学者,我在这里就不完全翻译了,只是把要点说明一下。请注意,我创建的UILable始终随着UIView的根CALayer的缩放而改变位置。)其次,CALayer的可以影响其外观的特性有:层的大小尺寸背景色内容(比如图像或是使用Core Graphics绘制的内容)是否使用圆角是否使用阴影等等需要说明的是CALayer的大部分属性都可以用来实现动画效果。另外,你可以直接使用CALayer,也可以使用其子类,如CAGradientLayer,CATextLayer, CAShapeLayer等等。首先要说的是CALa 阅读全文
posted @ 2012-03-06 14:30 pengyingh 阅读(410) 评论(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 阅读(4588) 评论(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 阅读(4230) 评论(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 阅读(1483) 评论(0) 推荐(0)
摘要: CoreAnimation中如何自定义动画属性是本文要介绍的内容,CoreAnimation可以对UIView里的CALayer进行动画处理。它的原理很简单,用户提供一个初始值,终点值和动画持续时间,CoreAnimation自动对 初始值,终点值之间,按照动画持续时间进行插值(生成中间值),生成中间帧,然后在一个单独的线程里进行播放,程序员就不再需要自己去绘制中间帧。 CoreAnimation在对CALayer进行动画生成时,需要用户指定对CALayer的哪一个属性进行插值,也就是必须声明成@property的变量,使用各个动画的虚拟超类CAPropertyAnimation的anima. 阅读全文
posted @ 2012-03-06 13:12 pengyingh 阅读(1200) 评论(0) 推荐(0)
摘要: 研究Core Animation已经有段时间了,关于Core Animation,网上没什么好的介绍。苹果网站上有篇专门的总结性介绍,但是似乎原理性的东西不多,看得人云山雾罩,感觉,写那篇东西的人,其实是假设读的人了解界面动画技术的原理的。今天有点别的事情要使用Linux,忘掉了ssh的密码,没办法重新设ssh,结果怎么也想不起来怎么设ssh远程登陆了,没办法又到网上查了一遍,太浪费时间了,痛感忘记记笔记是多么可怕的事情。鉴于Core Animation的内容实在是非常繁杂,应用的Obj-C语言本身的特性也很多,所以写个备忘录记录一下,懂的人看了后如果发现了错误,还不吝指教。1.UIView是 阅读全文
posted @ 2012-03-06 12:36 pengyingh 阅读(27718) 评论(4) 推荐(4)
摘要: 一、头文件#import<UIKit/UIKit.h>@interface DragIcon :UIView //拖动的视图{ CGPoint lastLoction; BOOL moveChanged; CGPoint touchBeginPoint; CGPoint touchMovedPoint; CGPoint touchEndPoint;}@property(nonatomic)CGPoint lastLoction;@property(nonatomic,assign)id delegate;@end@interface NQScrol... 阅读全文
posted @ 2012-03-06 11:28 pengyingh 阅读(327) 评论(0) 推荐(0)
摘要: 我也是现学现用,想了解的可以看看效果,想知道实现的也有源码https://github.com/quark-dev-team/quarkjs盛大研究院的游戏引擎夸克,非常强,而且支持移动设备平衡感应。http://www.limejs.com/一个HTML5游戏引擎http://www.html5rocks.com/google的html5试验场,有教程和代码沙盒。http://html5demos.com/ 刚搜到的,很不错,介绍了几种新特性的用法,都有源码。完全没概念的,也许可以从这里开始http://mugtug.com/sketchpad/这个出了有段时间了,Canvas的华丽应用,看 阅读全文
posted @ 2012-03-06 11:26 pengyingh 阅读(190) 评论(0) 推荐(0)
摘要: 本文是我们训练程序员的系列文章之一,仅供参考!这几年在全国巡回招聘应届毕业生的过程中,经常会遇到这样的现象:有些同学对自己的笔试比较满意,可是最后却得不到面试的机会,心里大为不解,颇有“死不瞑目”的味道。那么问题到底出现在哪里呢?让我们来看一个例子,这是我们招聘过程中一道常见的题目。写一个函数,完成内存移动,并为其写一个简单的测试用例来进行测试。够简单的吧?有的同学很快就写出了答案,详见程序清单1与程序清单2。程序清单 1V0.1版程序void MyMemMove(char *dst,char *src,int count){while(count--){*dst++ = *src++;}}程 阅读全文
posted @ 2012-03-06 11:01 pengyingh 阅读(1058) 评论(0) 推荐(0)
摘要: 实现功能的说明,可以对多个grid的联动,实现了无限翻页.grid功能是,右标题的右边内容可以联动,内容区可以单独翻页.非常好扩展第一部门为头文件:目前没有太多时间解释代码的.希望对大家有用//// NQGrid.h// IpadBlackDemo//// Created by ch_soft on 11-11-17.// Copyright 2011年 __MyCompanyName__. All rights reserved.//#import<UIKit/UIKit.h>#import"NQDataSource.h"#import"MapCol 阅读全文
posted @ 2012-03-06 11:00 pengyingh 阅读(1114) 评论(0) 推荐(0)
摘要: //该方法用于查询NQGrid对象。参数必须是NQGrid里面包含的子对象+ (NQGrid*)searchNQGridWithChild:(UIView*)childView;{ //简便方法,直接查找父页面,查找NQGrid对象。 idparent = [childViewsuperview]; while(parent && [parentisKindOfClass:[NQGridclass]]==NO) { parent = [parentsuperview]; } returnparent;}+(id)searchObjectWithChild:(UIView*)ch 阅读全文
posted @ 2012-03-06 10:47 pengyingh 阅读(134) 评论(0) 推荐(0)
摘要: 在最前边: Category得用法很方便,举例来说:新建一个Class文件, 文件名随意需要建立UIImage得Category就按照如下格式添加函数,括号内名称随意, 这种格式, 编译器即认为是一个Category@interface UIImage (xxx)@end@implementation UIImage (xxx)@end完整代码如下, 用法见附件Sample Code:@interface UIImage (Category)/** Resizes and/or rotates an image.*/- (UIImage*)transformWidth:(CGFloat)wid 阅读全文
posted @ 2012-03-06 10:38 pengyingh 阅读(282) 评论(0) 推荐(0)
摘要: 核心代码如下//暂停layer上面的动画- (void)pauseLayer:(CALayer*)layer{ CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil]; layer.speed = 0.0; layer.timeOffset = pausedTime;}//继续layer上面的动画- (void)resumeLayer:(CALayer*)layer{ CFTimeInterval pausedTime = [layer timeOffset]; layer.... 阅读全文
posted @ 2012-03-06 09:41 pengyingh 阅读(3460) 评论(0) 推荐(1)
摘要: [[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] resourcePath]];文件添加,显示,导航等等等等等等等!想要的,想学的都来下载一下吧!//加载文件内容- (void) loadFileContentsIntoTextView {// open a stream to filePathNSInputStream*inputStream = [[NSInputStreamalloc]initWithFileAtPath:filePath];[inputStreamo... 阅读全文
posted @ 2012-03-06 09:38 pengyingh 阅读(167) 评论(0) 推荐(0)
摘要: 如果以下的链接有错误,或者存在其他问题。请给我发站内短信,或者发送邮件至nono.cocoa@gmail.com希望该帖对大家有帮助/************************************************IOS 类代码************************/我自己做的翻书效果,小猫咪再次登场「2011/03/02」如何实现QQLive HD界面(附代码)「2011/03/02」tabelviewcell点击设置背景图片「2011/03/02」基于UDP的聊天程序(借鉴iphone自带的短信例子)「2011/03/01」橡皮擦效果「2011/01/06」< 阅读全文
posted @ 2012-03-06 09:33 pengyingh 阅读(271) 评论(0) 推荐(0)
摘要: CGFloat radians = atan2f(self.view.transform.b, self.view.transform.a); CGFloat degrees = radians * (180 / M_PI);NSLog(@"%f %f %f", acos (MyView.transform.a), asin (MyView.transform.b), atan2(MyView.transform.b,MyView.transform.a));- (CGImageRef)CGImageRotatedByAngle:(CGImageRef)imgRef ang 阅读全文
posted @ 2012-03-06 02:59 pengyingh 阅读(548) 评论(0) 推荐(0)
摘要: //第一种动画方式- (void) first_animations{ [UIViewbeginAnimations:nilcontext:nil]; //启动动画动作 [UIViewsetAnimationRepeatCount:1];//设置是否重复播放 [UIViewsetAnimationDuration:1];//设置动画持续时间 [UIViewsetAnimationCurve:UIViewAnimationCurveEaseIn];//动画曲线,具体的应用 ,可以经过实验检测 [UIViewsetAnimationDelegate:self];//动画块的某个方法(最下方),委托 阅读全文
posted @ 2012-03-06 02:48 pengyingh 阅读(3660) 评论(0) 推荐(0)

导航