UIScrollView contentSize调整大小

时间:2016-05-31 17:39:48

标签: ios objective-c uiscrollview contentsize

我正面临一个奇怪的问题,并且一直在检查SO以寻求解决方案,但还没有,所以我想我应该问。我在主视图中的UIScrollView(背景颜色为绿色)和其他视图中有mainView(背景颜色为白色)。在用数据动态填充视图的最后,我调用了

self.scrollView.contentSize = CGSizeMake(320, _v5.frame.size.height + _v5.frame.origin.y + 20);

其中_v5是scrollview中mainView中的最后一个视图。但是,它看起来像mainView没有调整到Scrollview大小,因此白色下方的视图没有接收到触摸。enter image description here我做错了什么?感谢

这是我的viewDidLoad

- (void)viewDidLoad
{
self.navigationItem.title = _type;
self.scrollView.contentSize = CGSizeMake(320, 610);

addressTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleMap:)];
websiteTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleWebsite:)];

[_lblWebsite setUserInteractionEnabled:YES];
[_lblAddress setUserInteractionEnabled: YES];
[_lblWebsite addGestureRecognizer:websiteTap];
[_lblAddress addGestureRecognizer:addressTap];

        _txtName.text = object[@"name"];
        available =  object[@"sDate"];
        website = object[@"website"];
        anyinfo = object[@"info"];
        PFUser *my = object[@"owner"];
        organiser = my[@"username"];
        if (organiser.length > 0){
            _txtOrganiser.text = organiser;
        }
        address = object[@"address"];
        NSDate *date = object[@"sDate"];

        if (address.length > 0){
            _lblAddress.text = address;
        }
        else{
            _lblAddress.text= @"Not provided";
        }
        if (date){
            _lblOpen.text = [display stringFromDate:date];
        }
        if (website.length > 0){
            _lblWebsite.text = website;
        }
        else{
            _lblWebsite.text= @"Not provided";
        }

        if (anyinfo.length > 0){
            _txtInfo.text = anyinfo;
            [self updateFrames];
        }
        self.scrollView.contentSize = CGSizeMake(320, _v5.frame.size.height + _v5.frame.origin.y + 20);
    } else {
        [self performSelectorOnMainThread:@selector(showAlert) withObject:nil waitUntilDone:YES];
        NSLog(@"Error %@", error.description);
    }
}];

[super viewDidLoad];
}

这是updateFrame

- (void) updateFrames{
_txtInfo.numberOfLines = 0;
_txtInfo.lineBreakMode = NSLineBreakByWordWrapping;
[_txtInfo sizeToFit];

_txtInfo.frame = CGRectMake(_txtInfo.frame.origin.x,_txtName.frame.origin.y + 10+ _txtName.frame.size.height, _txtInfo.frame.size.width, _txtInfo.frame.size.height);

_v1.frame = CGRectMake(_v1.frame.origin.x, _txtInfo.frame.origin.y + _txtInfo.frame.size.height +7, _v1.frame.size.width, _v1.frame.size.height);

_imgOrganiser.frame = CGRectMake(_imgOrganiser.frame.origin.x,_v1.frame.origin.y + 7, _imgOrganiser.frame.size.width, _imgOrganiser.frame.size.height);

_txtOrganiser.frame = CGRectMake(_txtOrganiser.frame.origin.x,_v1.frame.origin.y + 20, _txtOrganiser.frame.size.width, _txtOrganiser.frame.size.height);

_v2.frame = CGRectMake(_v2.frame.origin.x, _imgOrganiser.frame.origin.y + _imgOrganiser.frame.size.height +7, _v2.frame.size.width, _v2.frame.size.height);

_lblAddress.numberOfLines = 0;
_lblAddress.lineBreakMode = NSLineBreakByWordWrapping;
[_lblAddress sizeToFit];

_lblAddress.frame = CGRectMake(_lblAddress.frame.origin.x,_v2.frame.origin.y + 7, _lblAddress.frame.size.width, _lblAddress.frame.size.height);

_pin.frame = CGRectMake(_pin.frame.origin.x,_v2.frame.origin.y + 15, _pin.frame.size.width, _pin.frame.size.height);

_v3.frame = CGRectMake(_v3.frame.origin.x, _lblAddress.frame.origin.y + _lblAddress.frame.size.height +7, _v3.frame.size.width, _v3.frame.size.height);

_calender.frame = CGRectMake(_calender.frame.origin.x,_v3.frame.origin.y + 5, _calender.frame.size.width, _calender.frame.size.height);

_lblOpen.frame = CGRectMake(_lblOpen.frame.origin.x,_v3.frame.origin.y + 7, _lblOpen.frame.size.width, _lblOpen.frame.size.height);

_v4.frame = CGRectMake(_v4.frame.origin.x, _calender.frame.origin.y + _calender.frame.size.height +7, _v4.frame.size.width, _v4.frame.size.height);

_link.frame = CGRectMake(_link.frame.origin.x,_v4.frame.origin.y + 5, _link.frame.size.width, _link.frame.size.height);

_lblWebsite.frame = CGRectMake(_lblWebsite.frame.origin.x,_v4.frame.origin.y + 7, _lblWebsite.frame.size.width, _lblWebsite.frame.size.height);

_v5.frame = CGRectMake(_v5.frame.origin.x, _lblWebsite.frame.origin.y + _lblWebsite.frame.size.height +7, _v5.frame.size.width, _v5.frame.size.height);

self.scrollView.contentSize = CGSizeMake(320, _v5.frame.size.height + _v5.frame.origin.y + 20);}

0 个答案:

没有答案