0
我想實現一個尋址解決方案使用嵌套UIScrollView
的和有一個討厭的問題,我覺得很麻煩解決。嵌套的UIScrollView的尋呼
視圖加載得很好,但只要用戶啓動滾動,視圖會從頂部彈出約20個像素,並在被拉下時彈回到該位置。
我遵循其他回答問題的指導原則,但似乎無法確定問題所在。
當我自己使用innerScroll時,垂直工作得很好。
不久,我嵌套它,問題發生。
我試圖將contentSize
的高度增加到高於內容的高度,因爲我猜想這會是問題,但似乎沒有什麼區別。
CGRect screenSize = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
_theScrollView=[[customScrollView alloc] initWithFrame:screenSize];
_theScrollView.pagingEnabled = YES;
_theScrollView.directionalLockEnabled = YES;
_theScrollView.bounces = NO;
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(performAction:)];
NSArray* buttons = [[NSArray alloc]initWithObjects:barButton, nil];
CGSize scrollViewContentSize = screenSize.size;
scrollViewContentSize.width = screenSize.size.width * self.thisform.formPages.count;
scrollViewContentSize.height = self.view.bounds.size.height;
_theScrollView.contentSize = scrollViewContentSize;
self.actionButton = barButton;
self.picVisible = NO;
self.navigationItem.rightBarButtonItems = buttons;
UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(onCancelButtonSelected:)];
self.navigationItem.leftBarButtonItem = backButton;
[self.view setUserInteractionEnabled:YES];
self.views = [[NSMutableArray alloc] initWithCapacity:_thisform.formPages.count];
int i = 0;
NSSortDescriptor *byPage = [[NSSortDescriptor alloc] initWithKey:@"formPageNumber"
ascending:YES];
NSArray *sortedPages = [self.thisform.formPages sortedArrayUsingDescriptors:[NSArray arrayWithObjects: byPage, nil]];
float zoomScale=1.0;
UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
zoomScale=1.0;
} else {
zoomScale=1.3;
}
BOOL isNew;
for (FormPages *page in sortedPages) {
NSData *formImage = page.formPage;
//innerScroll
UIImage *image = [UIImage imageWithData:formImage];
Imager *imageView = [[Imager alloc] initWithImage:image];
[imageView setUserInteractionEnabled:YES];
imageView.tag = page.formPageNumber;
imageView.fieldCollection = [Utility populateFormFields:self.thisform
pagenumber:page.formPageNumber];
CGRect frame = CGRectMake(_theScrollView.bounds.size.width * i, 0, _theScrollView.bounds.size.width, _theScrollView.bounds.size.height);
float contentWidth = _theScrollView.bounds.size.width;
float contentHeight = imageView.frame.size.height;
CGSize contentSize = CGSizeMake (contentWidth,contentHeight);
TPKeyboardAvoidingScrollView *innerScroll = [[TPKeyboardAvoidingScrollView alloc] initWithFrame:frame];
innerScroll.contentSize = contentSize;
[innerScroll setUserInteractionEnabled:YES];
innerScroll.minimumZoomScale=1;
innerScroll.zoomScale = zoomScale;
innerScroll.maximumZoomScale=2.5;
innerScroll.delegate = self;
innerScroll.scrollsToTop=NO;
innerScroll.currentView = imageView;
imageView.frame = screenSize;
CGSize pageSize = [Utility GetPageSize:self.thisform];
float viewWidth = imageView.frame.size.width;
float formWidth = pageSize.width;
float viewHeight = imageView.frame.size.height;
float formHeight = pageSize.height;
float widthRatio = viewWidth/formWidth;
float heightRatio = viewHeight/formHeight;
[self populateControls:NO
view:imageView
widthRatio:widthRatio
heightRatio:heightRatio];
[innerScroll addSubview:imageView];
[_theScrollView addSubview:innerScroll];
[self.views addObject:innerScroll];
i++;
}
[self.view addSubview:_theScrollView];
您正在使用哪個版本的iOS? 另外,你是否檢查過你的視圖(和它的超級視圖)的界限?即使如果superview層次結構中的單個視圖具有不正確的邊界,它可能會與包含的視圖一起使用。 – n00bProgrammer
對不起,應該說它的IOS7,我很確定它在這之前工作正常。我會按建議檢查。謝謝 – Bushbert
所以這裏是每個視圖的邊界 – Bushbert