首先,我從下面的代碼開始,在我的視圖控制器中,但由於我工作的原因,我需要將下面的代碼放在單獨的類中。所以我創建了一個我在下面發佈的CustomView類。如何設置UIScrollView的子類,並在Interface Builder中將其連接起來
在這一點上,我有可能在我的視圖控制器中創建這個類的一個實例,創建一個IBOutlet並將它連接到界面生成器中的UIScrollView(或某種視圖),並獲得相同類型的行爲,我將如何做這樣的事情?
customView.m
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface CustomView : UIScrollView <UIScrollViewDelegate> {
UIScrollView *scrollView;
UIImageView *imageView;
}
@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
@property (nonatomic, retain) UIImageView *imageView;
customView.m
#import <UIKit/UIKit.h>
@implementation CustomView
@synthesize scrollView, imageView;
- (id)init {
if (self = [super init]) {
// Initialization code
UIImageView *temp = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myImage.png"]];
self.imageView = temp;
[temp release];
scrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
//Other Scroll View Properties
scrollView.delegate = self;
[scrollView addSubview:imageView];
}
return self;
}
- (void)dealloc {
[scrollView release];
[imageView release];
[super dealloc];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//Perform an action
}
@end
第二個UIScrollView怎麼了? – Brandon 2010-11-17 16:23:37