ios - UIScrollView 在 Xcode 5 中不滚动

标签 ios uiscrollview

我创建了 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/

相关文章:

javascript - 从 native iOS 应用程序打开另一个应用程序

swift - 有什么方法可以让我在 Swift 中看到 PhotoScroller?

ios - ios 中的寻呼机滑动 TabStrip

ios - ScrollView contentSize 大于边界,但没有滚动

ios - 如何在 iOS 的第二个 ScrollView 中显示第一个 ScrollView 图像?

javascript - 从 WKWebView 获取 JSON 文本

ios - 为什么不用指针变量

ios - 检查静态库的 iOS 部署目标

ios - 在 minimumFontSize 之后获取 UILabel 字体 pointsize

ios - 在 UIScrollView 中居中 UIButtons