指スライドアニメーション
指をスライドしてアニメーションするビューを作ります。
立体物を周囲からカメラで撮影して指のスライドで回転させたりするために使います。
普通にアニメーションの再生ポイントを指でグリグリ動かす用途にも使えます。
前準備としてアニメーションをjpgの連番等にして保存しておきます。
UIAnimationView.h
#import <UIKit/UIKit.h> @interface UIAnimationView : UIView { NSMutableArray *_imageArr; UIImageView *_imageView; int _currentFrame; int _lastFrame; } -(void)addImage:(NSString*)fname extension:(NSString*)ext; @end
UIAnimationView.m
#import "UIAnimationView.h" @implementation UIAnimationView - (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { _currentFrame = 0; _lastFrame = -1; _imageArr = [[NSMutableArray alloc]init]; _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)]; [self addSubview:_imageView]; } return self; } -(void)update { if(_lastFrame == _currentFrame)return; if([_imageArr count] == 0)return; _imageView.image = nil; _imageView.image = [_imageArr objectAtIndex:_currentFrame]; _lastFrame = _currentFrame; } -(void)addImage:(NSString *)fname extension:(NSString*)ext; { NSString *imagePath = [[NSBundle mainBundle] pathForResource:fname ofType:ext]; [_imageArr addObject:[[UIImage alloc] initWithContentsOfFile:imagePath]]; [self update]; } -(void)setFrame:(CGRect)rect { _imageView.frame = CGRectMake(0, 0, rect.size.width, rect.size.height); super.frame = rect; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint currentPosition = [touch locationInView:self]; float pos = currentPosition.x / self.frame.size.width; if(pos<=0.0)pos = 0.0; if(pos>=1.0)pos = 1.0; _currentFrame = (int)( ([_imageArr count]-1) * pos); [self update]; } - (void)dealloc { for(int i=0; i<[_imageArr count]; i++){ UIImage *img = [_imageArr objectAtIndex:i]; [img release]; } [_imageView release]; [_imageArr release]; [super dealloc]; } @end
呼び出し
UIAnimationView *a = [[UIAnimationView alloc] initWithFrame:CGRectMake(0,0, 640,480 )]; for(int i=0; i<50; i++){ [a addImage: [NSString stringWithFormat:@"mov_%d",i] extension:@"jpg"]; } [self addSubview:a];
このサンプルではファイルを mov_0.jpg〜mov_49.jpgとしてプロジェクトフォルダに保存してあるものとします。
MacBookProのバックアップ環境
Macに環境を移してTimeMachineの便利さに驚いた。まあやってる事自体は大した事ではないのはわかっている物の、セットアップの簡単さとバックログビュアーの出来の良さで高いクオリティを保持している。
さて、そこで問題になるのはバックアップディスクがUSBの外付けハードディスクかTimeCapsuleかという選択肢しかないことだ。それぞれの問題点は以下。
TimeCupsule
TimeCupsuleを購入するとTimeMachineのバックアップ機能をフルに活用できる。帰宅してノートPCをあければ定期的にTimeCupsuleをroot権限でマウントし、バックアップをとりづづけてくれる。一見最高のバックアップ環境に見える。
しかし、ここで問題になるのはTimeCupsuleの品質だ。様々なBlogを見て回ると電源周りのチップが脆弱なせいで大体2年弱で電源が入らなくなる。修理に出すとHDDは破棄され、データも返してくれない。だからといって解体すると本体が破損する上保証が効かなくなる。バックアップディスクとしては最悪だ。
外付けHDD
帰宅後毎度USBの外付けディスクを取り付けるのはどう考えても面倒だ。そもそもバックアップは気づかないうちにネットワーク越しにやっておいてほしい。
と、まあこのように問題が多い訳だが、個人的要望としてはRaidを組んであるNASドライブに対してネットワーク越しにバックアップをしたい。デフォルト状態ではTimeCapsule以外のNASをTimeMachineから選択する事ができない。しかしターミナルからシステムの環境設定をいじくることでこれが可能となる。
詳しくは下記サイトを参照。
- http://ameblo.jp/z9dz9d/entry-10156183879.html
- いくつか引っかかった点をメモ
DebianにPHPとApacheをインストール
さんざやった作業だけど、毎度思い出しながらやるのが面倒なのでメモ
とりあえずインストール
# apt-get install apache2 # apt-get install php5 # a2enmod php5 # a2enmod userdir
ユーザーディレクトリ設定
- /etc/apache2/mod-enabled/usrdir.conf
AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec ↓書き換え AllowOverride All Options ExecCGI
サイトにアクセス
http://localhost/~[usrname]/index.php
以上完了。
16進をUIColorに変換
16進のカラーをUIColorに変換します。
colorWithRedはautoreleaseで確保して返しますので使い終わると解放されます。
コード
-(UIColor*) hexToUIColor:(NSString *)hex alpha:(CGFloat)a{ NSScanner *colorScanner = [NSScanner scannerWithString:hex]; unsigned int color; [colorScanner scanHexInt:&color]; CGFloat r = ((color & 0xFF0000) >> 16)/255.0f; CGFloat g = ((color & 0x00FF00) >> 8) /255.0f; CGFloat b = (color & 0x0000FF) /255.0f; //NSLog(@"HEX to RGB >> r:%f g:%f b:%f a:%f\n",r,g,b,a); return [UIColor colorWithRed:r green:g blue:b alpha:a]; }
使い方
背景カラーを16進で指定したい場合、クラス内にメソッドとして上記を配置し、下記のように呼び出します。
self.backgroundColor = [self hexToUIColor:@"FF0000" alpha:1.0];
上記の例だとあまり意味がありませんが、例えばxmlでカラーを指定して反映させたい場合等は便利です。
自動ロック解除
自動ロックの解除方法メモ。
[UIApplication sharedApplication].idleTimerDisabled = YES;
これでアプリ起動中にスリープしなくなります。
確認していませんが、リリースモードでのみ有効となるそうです。
データの保存
簡単な環境設定とかを保存する方法
保存
NSUserDefaults *ud =[NSUserDefaults standardUserDefaults]; [ud setObject:@"hage" forKey:@"hoge"]; [ud synchronize];
setObjectの引数はNSStringだけではなく、NSArrayやNSDictionaryでも可
読み出し
NSString *hageData = [[NSUserDefaults standardUserDefaults] stringForKey:@"hoge"];
データが存在しない場合はnilが入るので下記のようにデフォルト値を入れても良い
if(hageData==nil) hageData = @"defaultHage";