gdata-objectivec-clientを一部手動でstatic library化
gdata-objectivec-clientを使ってGoogleのサービスを使うアプリを作っていたのですが、しばらく、entryからXMLを抜き出しただけで、時折落ちるという原因がまったくわからない現象が発生して、しばらく困っていて、もうどうしようもないと思って、バージョンアップしたら直ってました。。。
ということで、gdata-objectivec-clientを一部手動でstatic library化する方法をまとめておきます。おかしいところがありましたら、教えてください。
- 最新のソースをもらってくる
http://code.google.com/p/gdata-objectivec-client/
- 基本的には、以下のところを参照してコンパイルする
http://code.google.com/p/gdata-objectivec-client/wiki/BuildingTheLibrary
- 展開して、GData.xcodeprojを立ち上げる
- アクティブターゲットをGDataTouchStaticLibにする
- iPhoneOSを3.1.3にして、simulatorでビルド
- iPhoneOSを3.1.3にして、実機でビルド
- アクティブターゲットをGDataTouchStaticLibにする
- コンパイルすると、 libGDataTouchStaticLibができる(Product)に
- 実機、シミュレータの療法で使えるstaticなライブラリを作成する
参考: http://blog.boreal-kiss.com/2009/08/29000009.html
このままだと実機とシミュレータで別々のライブラリが出来上がってしまうので、
簡略化するために、ライブラリをひとつにまとめる。
% cd Source/build % lipo -create Debug-iphoneos/libGDataTouchStaticLib.a Debug-iphonesimulator/libGDataTouchStaticLib.a -output libGDataTouchStaticLib_com.a
- できたlibGDataTouchStaticLib_com.aをプロジェクトのFrameworksのところに突っ込む。
- Source/build/Debug-iphoneos/Headers以下をすべて自分のプロジェクトにコピーする。
- あと、libxml2のリンク準備もしておく必要があります。
iPhoneのデバッグログの改善
iPhoneの開発用のログはたいていNSLogで出力するわけですが、リリースの時には抜きたかったりするので、個別にdefineで切り分けたりしておくのが通常の方法だと思いますが、下記の仕組みでは、デバッグとリリースの切り分けだけでなく、ログにクラスと関数名も出力してもらえます。
http://www.cimgf.com/2010/05/02/my-current-prefix-pch-file/
やりかたは簡単。
プロジェクト→プロジェクト設定を編集→ビルド
でその他のCフラグに-DDEBUGを追加
その後、XXX_Prefix.pchに以下の行を追加すればOK
#ifdef DEBUG #define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__]) #define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__] #else /* DEBUG */ #define DLog(...) do { } while (0) #ifndef NS_BLOCK_ASSERTIONS #define NS_BLOCK_ASSERTIONS #endif #define ALog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__]) #define ZAssert(condition, ...) do { if (!(condition)) { ALog(__VA_ARGS__); }} while(0) #endif /* DEBUG */
NSLogをDLogに置き換えます。あとはALog,ZAssertというAssert系のものが利用可能です。
触る位置によって、ビューの反転のアニメーションを変える
2-9 レシピ:ビューの反転
FlipViewをinitしたら、黄色と青色の背景のふたつのビューを作成して、それらを交互に反転させる。ただし、アニメーションはタップした位置によって変えてみる。
@interface FlipView : UIView { } @end @implementation FlipView -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; UIView *view1 = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; UIView *view2 = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; view1.backgroundColor = [UIColor yellowColor]; view2.backgroundColor = [UIColor blueColor]; [self addSubview:view1]; [self addSubview:view2]; return self; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint pt = [[touches anyObject] locationInView:self]; UIViewAnimationTransition trans = UIViewAnimationTransitionNone; // うえの方をたたくと上へ、したの方を叩くと下に if (pt.y < 20) { trans = UIViewAnimationTransitionCurlUp; } else { if (pt.y > 440) { trans = UIViewAnimationTransitionCurlDown; } } // 極端に上でも下でもない場合には、左右で決める if (trans == UIViewAnimationTransitionNone) { if (pt.x < 160) { trans = UIViewAnimationTransitionFlipFromRight; } else { trans = UIViewAnimationTransitionFlipFromLeft; } } CGContextRef cont = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:cont]; // どう動かすかを決定する [UIView setAnimationTransition:trans forView:[self superview] cache:YES]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:1.0]; [self exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; [UIView commitAnimations]; } @end
タッチした場所に画像が浮き上がってくる
忘れてましたが、勉強用に「iPhoneデベロッパーズクックブック」(エリカ・サドゥン著)を
使っているので、ソースもこれがベースになります。
今回はアニメーションで画像が浮き上がったり沈んだりするサンプルですが、タッチしたところに出したくなったので、そのサンプルです。タッチしたところのポイントUIImageViewに渡す方法にちょっと悩みました。CGRectMakeで作って、それをframeに入れるだけ。ソースにするとたいしたことないんだけど。
@interface ToggleView : UIView { BOOL isVisible; UIImage *img; UIImageView *imgView; } @end @implementation ToggleView -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; isVisible = NO; img = [UIImage imageNamed:@"test.png"]; imgView = [[UIImageView alloc] initWithImage:img]; imgView.userInteractionEnabled=NO; [self addSubview:imgView]; [imgView setAlpha:0.0f]; [imgView release]; return self; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; // 押したときだけ反応する if ([touch phase] != UITouchPhaseBegan) return; //toggle isVisible = !isVisible; if (isVisible) { // 表示する時は、タッチされた場所を中心に表示する CGPoint pt = [[touches anyObject] locationInView:self]; imgView.frame = CGRectMake(pt.x - img.size.width / 2.0f, pt.y - img.size.height / 2.0f, img.size.width , img.size.height); } CGContextRef context = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:1.0]; [imgView setAlpha:(float)isVisible]; [UIView commitAnimations]; } -(void)dealloc { [imgView release]; [super dealloc]; } @end
iPhone開発メモ
せっかくiPhoneの開発環境が触れるようになったけど、どんどん忘れていくので、
備忘録用のメモです。
それぞれのViewに大して、以下のふたつの関数で制御できる
- exclusiveTouch (一度タッチされた後、他のViewへのタッチを無効に)
- multipleTouchEnabled (マルチタッチを可能にするかどうか)
あるビューでtouchを処理しない場合には(関数を定義しない=delegateしない)、そのまま
その下のビューに渡される。逆にdelegateされた場合には、下へイベントは渡っていかない。
- UIImageView 画像のはりつけなどを行う(UIImageとの明確な違いを後で調べること)
UIViewから派生したクラスで、自分を消したい場合には、addSubViewの逆であるremoveFromSuperview
を呼ぶことで可能になる。