我创建了MyCalender
的子类UIView
,并在UIScrollView
类中取MyCalender
。并使用此MyCalender
作为任何其他viewController的子视图。但问题是UIScrollView
不滚动。我正在使用Xcode 5
MyCalender.h文件
#import <UIKit/UIKit.h>
@interface MyCalender : UIView
{
UIScrollView *scrollMonth;
}
@property(strong,nonatomic) UIScrollView *scrollMonth;
@end
MyCalender.M file ------
#import "MyCalender.h"
@implementation MyCalender
@synthesize scrollMonth;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
scrollMonth =[[UIScrollView alloc] init];
[scrollMonth setFrame:CGRectMake(0, 66, 320, 220)];
[scrollMonth setContentSize:CGSizeMake(320, 500)];
[scrollMonth setBackgroundColor:[UIColor blackColor]];
[scrollMonth setUserInteractionEnabled:YES];
[self addSubview:scrollMonth];
//----------- ---------- -------- ---------
}
return self;
}
TestView类,其中我使用了MyCalender类
#import <UIKit/UIKit.h>
#import "MyCalender.h"
@interface testView : UIViewController
{
MyCalender *viewCALENDER;
}
@property(strong,nonatomic) MyCalender *viewCALENDER;
@end
Testview.m
#import "testView.h"
@interface testView ()
@end
@implementation testView
@synthesize viewCALENDER;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
viewCALENDER=[[MyCalender alloc] initWithFrame:CGRectMake(0, 64, 320, 64)];
[self.view addSubview:viewCALENDER];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 0 :(得分:3)
从它的外观来看,您的滚动视图在viewCALENDAR
:
viewCALENDER=[[MyCalender alloc] initWithFrame:CGRectMake(0, 64, 320, 64)];
[scrollMonth setFrame:CGRectMake(0, 66, 320, 220)];
容器视图(viewCALENDAR
)的高度为64px,而滚动视图的位置为66位。
澄清“不可见”&#39; - 如果容器视图为clipsToBounds==NO
,则滚动视图可见,但在这种情况下,它不会是交互式的。