【发布时间】:2010-07-08 15:06:43
【问题描述】:
我的 UIView 子类“Card”中有一个方法可以通过将其 alpha 从 1 淡化为 0 来关闭实例。当我将卡片添加到超级视图时,我会执行类似的操作,并且它会淡入淡出。但是当我调用 fadeAway 时,它会立即消失。演示代码在我的控制器类中。这是我的 Card.h 和 Card.m
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@class Card;
@interface Card : UIView {
int upperOperand;
int lowerOperand;
NSString* theOperator;
int theResult;
}
@property(nonatomic) int upperOperand;
@property(nonatomic) int lowerOperand;
@property(nonatomic, retain) NSString* theOperator;
@property(nonatomic) int theResult;
- (void)fadeAway;
@end
#import "Card.h"
@implementation Card
@synthesize upperOperand;
@synthesize lowerOperand;
@synthesize theOperator;
@synthesize theResult;
- (void)fadeAway {
self.alpha = 1.0f;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:2.0f];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
self.alpha = 0.0f;
[UIView commitAnimations];
[self removeFromSuperview];
}
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
self.backgroundColor = [UIColor redColor];
self.layer.cornerRadius = 15;
self.alpha = 1.0;
self.layer.borderColor = [[UIColor blueColor] CGColor];
self.layer.borderWidth = 4;
}
return self;
- (void)dealloc {
[super dealloc];
}
@end
【问题讨论】:
标签: iphone objective-c xcode animation uiview