嘿傢伙,我終於解決了我的問題。我分類UIView
並添加了兩個UIImageView
s和一個UIButton
它。動畫現在非常好!
下面是代碼:
.H
#import <UIKit/UIKit.h>
@interface NNAnimatableButton : UIView {
UIImageView *backgroundImageView;
UIImageView *imageView;
UIButton *button;
}
@property (nonatomic, retain) UIImageView *backgroundImageView;
@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) UIButton *button;
@end
.M
#import "NNAnimatableButton.h"
@implementation NNAnimatableButton
@synthesize backgroundImageView, imageView, button;
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
CGRect rect = CGRectMake(0.0f, 0.0f, frame.size.width, frame.size.height);
NSUInteger autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
// Initialization code.
backgroundImageView = [[UIImageView alloc] initWithFrame:rect];
backgroundImageView.autoresizingMask = autoresizingMask;
imageView = [[UIImageView alloc] initWithFrame:rect];
imageView.autoresizingMask = autoresizingMask;
imageView.contentMode = UIViewContentModeCenter;
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.autoresizingMask = autoresizingMask;
[button setFrame:rect];
[self addSubview:backgroundImageView];
[self addSubview:imageView];
[self addSubview:button];
[backgroundImageView release];
[imageView release];
}
return self;
}
- (void)dealloc {
[backgroundImageView release];
[imageView release];
[button release];
[super dealloc];
}
@end
也許'[UIView的beginAnimations:無背景:@ 「MyAnimation」];'真的'[ UIView beginAnimations:@「MyAnimation」context:NULL];(第一個參數是animationID,NSString *; second - context,void *)? – kpower 2010-08-05 10:10:16
@kpower對於錯字,我很抱歉,但仍然無效。 – nonamelive 2010-08-05 10:54:05
你是什麼意思的「不工作」?請明確點。 – kennytm 2010-08-05 11:09:58