UIScrollView不在UiView中滚动

时间:2014-01-09 15:55:59

标签: ios iphone objective-c uiview uiscrollview

当我滚动UIScrollView时不滚动。我也在设置scrollview的contentSize。 当我展示另一个子视图时,在我显示我的视图后,它就会滚动。

您可以查看此video的问题。我怎么解决这个问题?

myViewController.h文件

#import <UIKit/UIKit.h>

@interface myViewController : UIViewController



@property(nonatomic,retain)UIView * rightTabView;
@property(nonatomic,retain)UIView * leftTabView;
@property(nonatomic,retain)UIView * middleTabView;
@property(nonatomic,retain)UIScrollView *myscrollview;

@end

myViewController.m文件

- (void)viewDidLoad
{

    // Do any additional setup after loading the view from its nib.
    [super viewDidLoad];



    //create Tab views and addSubview


     CGFloat barHeight=58;
    self.rightTabView=[[UIView alloc] initWithFrame:CGRectMake(0, barHeight+55,self.view.bounds.size.width,self.view.bounds.size.height-barHeight-55)];
    [self.view addSubview:self.rightTabView];

    self.leftTabView=[[UIView alloc] initWithFrame:CGRectMake(0, barHeight+5,self.view.bounds.size.width,self.view.bounds.size.height-barHeight-55)];
    self.leftTabView.backgroundColor=[UIColor redColor];
    [self.view addSubview:self.leftTabView];


    self.middleTabView=[[UIView alloc] initWithFrame:CGRectMake(0, barHeight+55,self.view.bounds.size.width,self.view.bounds.size.height-barHeight-55)];
    [self.view addSubview:self.middleTabView];

    //add Subview to leftTabView
    myscrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(10, 10,300, 340)];
    myscrollview.userInteractionEnabled=YES;
    myscrollview.backgroundColor = [UIColor greenColor];
    myscrollview.delegate = self;
    [self.leftTabView addSubview:myscrollview];

    myscrollview.contentSize = CGSizeMake(2000, 2000);
}

1 个答案:

答案 0 :(得分:2)

看起来你的middleTabView模糊了你的leftTabView(这是你的scrollview的超级视图)。将leftTabView置于视图层次结构的顶部:

[self.leftTabView.superview bringSubViewToFront:self.leftTabView];

或禁用用户交互或middleTabView的可见性(或最后添加leftTabView)。