我想添加一個textView
和textField
爲subViews
到我的scrollView
。 scrollView
顯示很好和綠色,但textView
和textField
對象沒有顯示在scrollView內部。Textfields/TextViews不會添加到滾動視圖iOS
這是一次將我的相機設備上可掃描的條形碼
- (void) readerView: (ZBarReaderView*) view
didReadSymbols: (ZBarSymbolSet*) syms
fromImage: (UIImage*) img
{
// do something useful with results
for(ZBarSymbol *sym in syms) {
self.symbolData = (NSString*)sym.data;
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 20, 20)];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(30, 240,20,20)];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 200, 300, 80)];
[textField setBackgroundColor:[UIColor redColor]];
[scrollView setBackgroundColor:[UIColor greenColor]];
[textView setBackgroundColor:[UIColor purpleColor]];
textView.text = self.symbolData;
[self.view addSubview:scrollView];
[scrollView addSubview:textField];
[scrollView addSubview:textView];
break;
}
}
,此方法被調用的方法。
我也在這個網站上看到很多類似的問題,我的代碼看起來像我所見過的問題的答案,但我無法弄清楚爲什麼它不工作。
在此先感謝
這是一個問題,您的滾動視圖只有80像素高,但您添加到它的視圖具有200和240的y座標?默認情況下,滾動視圖剪輯到邊界,所以如果它們離開滾動視圖的屏幕,您將永遠不會看到您的子視圖。 – Putz1103
是的,這是問題所在。我知道這是愚蠢的。謝謝! –