我创建了 UIView
的子类 MyCalender
并在 MyCalender
类中使用了 UIScrollView
。并将此 MyCalender
用作任何其他 viewController 的 subview 。但问题是 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;
}
我在其中使用 MyCalender 类的 TestView 类
#import <UIKit/UIKit.h>
#import "MyCalender.h"
@interface testView : UIViewController
{
MyCalender *viewCALENDER;
}
@property(strong,nonatomic) MyCalender *viewCALENDER;
@end
测试 View .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
最佳答案
从外观上看,您的 ScrollView 在 viewCALENDAR
中不可见:
viewCALENDER=[[MyCalender alloc] initWithFrame:CGRectMake(0, 64, 320, 64)];
[scrollMonth setFrame:CGRectMake(0, 66, 320, 220)];
容器 View (viewCALENDAR
) 的高度为 64px,而您的 ScrollView 位于 y 位置 66。
澄清“不可见”——如果容器 View 的 clipsToBounds==NO
ScrollView 可能是可见的,但在这种情况下它不会是交互式的。
关于ios - UIScrollView 在 Xcode 5 中不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23130874/