トップ «前の日記(2013-01-04) 最新 次の日記(2013-01-06)» 編集

Cocoa練習帳

iOS/iPhone/iPad/watchOS/tvOS/MacOSX/Android プログラミング, Objective-C, Cocoa, Swiftなど

2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|03|

2013-01-05 [OSX][iOS]アニメーションの種類(画面遷移)

今回は、色々な失敗をしてしまった。Cocoa toouchで慣れてしまった関係でOS Xとの違いも戸惑った。

TOPのビューに、同じサイズの二つのビューを入れ替えるサンプルだ。

self.pentagonImageView = [[MyImageView alloc] initWithFrame:self.frame];
self.starImageView = [[MyImageView alloc] initWithFrame:self.frame];
 
[self.pentagonImageView setImageScaling:NSScaleToFit];
[self.pentagonImageView setImage:[NSImage imageNamed:@"pentagon.png"]];
 
[self.starImageView setImageScaling:NSScaleToFit];
[self.starImageView setImage:[NSImage imageNamed:@"star.png"]];

最初に五角形のビューをサブビュートしてい追加する。

[self addSubview:self.pentagonImageView];

その際、忘れていけないのは、アニメーションを追加する上位ビューのレイヤーを有効にすること。

[self setWantsLayer:YES];

画面遷移のアニメーションを追加する。

self.animations = [NSDictionary dictionaryWithObjectsAndKeys:
                         [self transitionAnimation], @"subviews",
                         nil];

アニメーションの定義は以下のとおり。

- (CATransition *)transitionAnimation
{
    CATransition *animation = [CATransition animation];
    animation.type = kCATransitionMoveIn;
    animation.subtype = kCATransitionFromTop;
    return animation;
}

マウス押下されると画面を差し替える。

if (nil != [self.pentagonImageView superview]) {
    [[self animator] replaceSubview:self.pentagonImageView with:self.starImageView];
}
else if (nil != [self.starImageView superview]) {
    [[self animator] replaceSubview:self.starImageView with:self.pentagonImageView];
}

Core Animationでいうtransitionとは、サブビューの追加と削除時の表示と非表示の入れ替わりを想定しているようだ。

_ 【Cocoa練習帳】

http://www.bitz.co.jp/weblog/
http://ameblo.jp/bitz/(ミラー・サイト)

トップ «前の日記(2013-01-04) 最新 次の日記(2013-01-06)» 編集