2009 Archives

Not A Type retain Error

| No Comments | No TrackBacks

代码,多次运行后,CGImageCreateWithImageInRect会出现错误

-(void)drawCard:(CGContextRef)context card:(Card *)card Point:(CGPoint)location

{


location =CGPointMake(location.x, location.y+38);

//card 41*60

//digit 10*14

VirtualCard *virtualCard =[[VirtualCard alloc] initWithID:[card getCardId] size:0];

CGImageRef cardbg = CGImageCreateWithImageInRect(cards ,CGRectMake([virtualCard getCardSuitFrameW] * [card getSuit] , 0, CGImageGetWidth(cards)/5, CGImageGetHeight(cards)));

CGContextDrawImage(context,CGRectMake(location.x, location.y ,[virtualCard getCardSuitFrameW] , [virtualCard getCardSuitFrameH]),cardbg);

if (cardbg != NULL) {

CFRelease(cardbg);

}

CGImageRef digit = CGImageCreateWithImageInRect(digits,CGRectMake([virtualCard getDigitFrameX_px], [virtualCard getDigitFrameY_px], 10, 14));

CGContextDrawImage(context,CGRectMake(location.x + 2, location.y-3+60-14, 10, 14), digit);

if (digit != NULL) {

CFRelease(digit);;

}

[virtualCard autorelease];

}

时间:12月19日下午13:00-17:20
地点更新到2509,请注意
地点:‎ 上海市长宁区长宁路1033号‎  联通大厦2509 室
支持: 联通有限公司上海分公司

下午13:00点开始签到
下午 13:30 正式开始

主题演讲

13:30 - 14:00 致辞,联通介绍WCDMA
1 Core Animation 介绍
  演讲者  孔祥波
  时间:14:00 - 14:40
2 iPhone 应用程序内存管理
  演讲者 李亮 
  时间: 14:50 -15:30
3 iPhone 游戏中的OpenAL
  演讲者  林毅
  时间:15:40-16:20
3 iPhone SDK MapKit 介绍 
  演讲者  曾令璇
  时间:16:30 - 17:10


演讲嘉宾介绍:

李亮  iPhone第一个输入法iCoast作者,著名Hacker
林毅  iPhone/Mac 程序员,曾供职FileMaker.
曾令璇 自由职业者,专注iPhone 应用开发。
孔祥波 MacGeeks.cn 站长, Unix Geek.

座位数量有限,请发邮件到 yarshure@gmail.com 确认。
有名片的兄弟,尽量带上,谢谢
孔祥波

如何创建动态连接库

| 8 Comments | No TrackBacks
其实就是一条命令
MacBook-Pro-17:MM yarshure$ /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool -dynamic -arch_only armv6 -syslibroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.2.sdk -L/Users/yarshure/Desktop/MM/build/Release-iphoneos  /Users/yarshure/Desktop/MM/build/MM.build/Release-iphoneos/MM.build/Objects-normal/armv6/test.o -ObjC -framework Foundation -o /Users/yarshure/Desktop/MM/build/Release-iphoneos/libMM.dyld
下面是编译好的文件
MacBook-Pro-17:MM yarshure$ file /Users/yarshure/Desktop/MM/build/Release-iphoneos/libMM.dyld
/Users/yarshure/Desktop/MM/build/Release-iphoneos/libMM.dyld: Mach-O dynamically linked shared library arm

测试OK,不过是在破解的机器上

看下面关键的代码

关于View DrawRect刷新

| 2 Comments | No TrackBacks
需求: 进度条需要定时更新,达到临近不需要继续更新
方法1 使用Timer

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updataprogress) userInfo:nil repeats:NO];


更新函数

-(void)updataprogress

{


if (Height <50) {

Height += 10;

NSLog(@"progress :%d",Height);

[self setNeedsDisplay];

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updataprogress) userInfo:nil repeats:NO];

}

}

这样写有点繁琐,也可以使用NSTimer 实例来做


方法2 使用线程

[NSThread detachNewThreadSelector:@selector(updataprogress1) toTarget:self withObject:nil];


函数

-(void)updataprogress1

{

NSAssert2([NSThread currentThread], @"%s at line %d called on secondary thread", __FUNCTION__, __LINE__);

while (Height <50) {

Height += 10;

NSLog(@"progress :%d",Height);

[self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];

//[self setNeedsDisplay];

sleep(3.0);

}

}

不能使用[self setNeedsDisplay] 方法,否则无法刷新。

一定要在主线程执行刷新,这个和Cocoa 渲染机制有关系。

Cocoa App 运行的时候有独立线程负责渲染,这个线程也是用来处理CoreAnimation.


另外经过测试UILable 更新同样需要在主线程更新

测试代码如下:

Quartz 2D 基础

| No Comments | No TrackBacks
CGImageCreateWithImageInRect 使用

如何画矩形

CGRect backRect = CGRectMake(1010508);

CGContextSetRGBFillColor(context, 1.01.01.01.0);

CGContextFillRect(context, backRect);


下面的代码是选择坐标系

CGContextTranslateCTM(context, 0.0self.frame.size.height);

CGContextScaleCTM(context, 1.0, -1.0);

CGContextShowTextAtPoint 不能draw中文,中文等UTF8 需要用

NSString drawAtPoint 这个方法

看看效果
屏幕快照 2009-12-09 上午02.48.31.png

新技术DemoKit

| No Comments | No TrackBacks
拜一下国外的超级黑客,CookBook 的作者。具体看图吧。
连接
http://macgeeks.cn/bbs/thread-8317-1-1.html

新的一天又开始了

| No Comments | No TrackBacks
最近小感冒,流鼻涕,很不舒服。

项目很紧,已经拖了好久。
项目比想像的要繁琐很多, 非常具有挑战性。
1 大量的状态机
2 Socket 通讯
3 显示游戏画面
4 Timer 的使用
5 Model 层还有一些问题,需要check.