ios - 変更 - xcode image color
iOS 7でシート/アラートが表示されているときにカスタム描画されたコントロールでtintColorをグレーにアニメーション化するにはどうすればよいですか? (2)
iOS 7では、 UIActionSheet
が提示されると、システムはすべてtintColor
を灰色にアニメーション化します。 シートが外されると、シートは元に戻ります。
私はカスタム背景画像や色合いの色を使用するdrawRect
実装でいくつかのコントロールを持っています。私はそれらの変更をシステムコントロールのようにアニメーション化したいと思います。
AppleはUIView
- (void)tintColorDidChange
を追加しましたが、このメソッドで新しい色で再描画しても変更はアニメートされません。フルカラーから- (void)tintColorDidChange
に直ちに切り替わります。
カスタム描画されたコントロールをAppleのようにtintColor
トランジションをアニメーション化するにはどうすればよいですか?
drawRect:
アニメーションが新しいtintColor
を更新するために自動的に呼び出されるべきではありませんか?
私はメインビューコントローラに3つのコントロールを持つデモアプリケーションを作った。 最初のボタンは、標準のアクションシートを表示します。 2番目のボタンは観察のためのボタンです(タップされたボタンはアニメーション中では比較が困難です)。 3番目はカスタムUIView
サブクラスで、ビューのtintColor
矩形を単に描画します。 tintColorDidChange
が呼び出されると、 tintColorDidChange
が呼び出され、次にdrawRect:
が呼び出されdrawRect:
。
1つのView Controllerで新しいアプリケーションを作成しました。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[UIApplication sharedApplication] keyWindow].tintColor = [UIColor blueColor];
// Button to bring up action sheet
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = (CGRect){10,30,300,44};
[button setTitle:@"Present Action Sheet" forState:UIControlStateNormal];
[button addTarget:self
action:@selector(didTapPresentActionSheetButton:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
// Another button for demonstration
UIButton *anotherButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
anotherButton.frame = (CGRect){10,90,300,44};
[anotherButton setTitle:@"Another Button" forState:UIControlStateNormal];
[self.view addSubview:anotherButton];
// Custom view with tintColor
TESTCustomView *customView = [[TESTCustomView alloc] initWithFrame:(CGRect){10,150,300,44}];
[self.view addSubview:customView];
}
- (void)didTapPresentActionSheetButton:(id)sender
{
UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"Action Sheet"
delegate:nil
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Delete"
otherButtonTitles:@"Other", nil];
[as showInView:self.view];
}
ここで、 TESTCustomView
は次のように実装されたUIView
サブクラスです。
- (void)drawRect:(CGRect)rect
{
NSLog(@"Drawing with tintColor: %@", self.tintColor);
// Drawing code
[super drawRect:rect];
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(c, self.tintColor.CGColor);
CGContextFillRect(c, rect);
}
- (void)tintColorDidChange
{
[self setNeedsDisplay];
}
このアプリケーションをシミュレータで実行すると、カスタムビューのtintColorは、ビューコントローラの標準UIButton
インスタンスで自動的にアニメートされUIButton
。
tintAdjustmentMode
を試しtintAdjustmentMode
か?
あなたはWWDC 2013セッション214を見て、iOS 7のためにあなたのApp Appearanceをカスタマイズし 、 TicTacToeデモアプリを読んでください
このようなもの
- (void)onPopupOpened
{
[UIView animateWithDuration:0.3 animations:^{
window.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
}];
popupView.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
popupView.tintColor = [UIColor redColor];
}
- (void)onPopupClosed
{
[UIView animateWithDuration:0.3 animations:^{
window.tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic;
}];
}