2012-01-21 15 views
0

私はUITextViewsが移動されているピクセルの数に基づいてUIViewとUIScrollViewのサイズを変更しています。私はすべてのピクセルがint変数に格納されています。私はこれを使用しているこれらのテキストビューのすべてを移入するために私の方法の終わりに:ビューのサイズ変更。私が計画した通りに動作しません

viewHeight += viewPixelsToBeAdded; 
viewHeight -= viewPixelsToBeRemoved; 
detailsView.frame = CGRectMake(0, 20, 320, viewHeight); 
realDetailsView.frame = CGRectMake(0, 20, 320, viewHeight); 

viewHeightは、私は総画素数を保持するためにviewPixelsToBeAddedviewPixelsToBeRemovedを使用しています1475ある一定のビューの高さでありますビューのサイズを変更する必要があることを示します。上記のコードを使用すると...私のscrollView(detailsView)はスクロールを停止します。全体として。私は私のオブジェクトをビューの中に持っています。そのビューはscrollViewの内部にあります。このようなもののサイズを変更する簡単な方法はありますか?なぜ、私のscrollViewの高さを増減すると、スクロールが止まるのですか?どんな助けでも大歓迎です。必要に応じて、populateLabelsメソッド全体を投稿することができます。とにかく長い道のりをとっているような気がします。

-(void) populateLabels { 

NSString *noInfo = (@"No Information Available"); 
lblCgName.text = _Campground.campground; 
NSString *cgLoc = _Campground.street1; 
NSString *cgCity = _Campground.city; 
NSString *cgState = _Campground.state1; 
NSString *cgCountry = _Campground.country; 
NSString *cgZipPostal = _Campground.zipPostal; 
cgLoc = [[cgLoc stringByAppendingString:@", "] stringByAppendingString:cgCity]; 
cgLoc = [[cgLoc stringByAppendingString:@", "] stringByAppendingString:cgState]; 
cgLoc = [[cgLoc stringByAppendingString:@", "] stringByAppendingString:cgCountry]; 
cgLoc = [[cgLoc stringByAppendingString:@" "] stringByAppendingString:cgZipPostal]; 
lblCgLoc.text = cgLoc; 
double dRate = [_Campground.regRate1 doubleValue]; 
double dRate2 = [_Campground.regRate2 doubleValue]; 
NSString *rate = [[NSString alloc] initWithFormat:@"$%0.2f",dRate]; 
NSString *rate2 = [[NSString alloc] initWithFormat:@"$%0.2f",dRate2]; 
if ([rate2 isEqualToString:@"$0.00"]) { 
    lblRate.text = rate; 
} else { 
    rate = [[rate stringByAppendingString:@" - "] stringByAppendingString:rate2]; 
    lblRate.text = rate; 
} 
double dPaRate = [_Campground.paRate1 doubleValue]; 
double dPaRate2 = [_Campground.paRate2 doubleValue]; 
NSString *paRate = [[NSString alloc] initWithFormat:@"$%0.2f",dPaRate]; 
NSString *paRate2 = [[NSString alloc] initWithFormat:@"$%0.2f",dPaRate2]; 
if ([paRate2 isEqualToString:@"$0.00"]) { 
    lblPaRate.text = paRate; 
} else { 
    paRate = [[paRate stringByAppendingString:@" - "] stringByAppendingString:paRate2]; 
    lblPaRate.text = paRate; 
} 
lblLocal1.text = _Campground.localPhone1; 
lblLocal2.text = _Campground.localPhone2; 
lblTollFree.text = _Campground.tollFree; 
lblFax.text = _Campground.fax; 
lblEmail.text = _Campground.email; 
lblWebsite.text = _Campground.website; 
NSString *gps = _Campground.latitude; 
NSString *longitude = _Campground.longitude; 
gps = [[gps stringByAppendingString:@", "] stringByAppendingString:longitude]; 
lblGps.text = gps; 

int viewHeight = 1475; 
int textViewDefaultHeight = 128; 
int newTextViewHeight = 0; 
int highlightsPixelsRemoved = 0; 
int highlightsPixelsAdded = 0; 
int notesPixelsRemoved = 0; 
int notesPixelsAdded = 0; 
int directionsPixelsRemoved = 0; 
int directionsPixelsAdded = 0; 
int rentalsPixelsRemoved = 0; 
int rentalsPixelsAdded = 0; 
int viewPixelsToBeRemoved = 0; 
int viewPixelsToBeAdded = 0; 

//----------------------------------------------------------------------------  

txtHighlights.text = _Campground.highlights; 
[self fitFrameToContent:txtHighlights]; 
newTextViewHeight = txtHighlights.contentSize.height; 
if (newTextViewHeight > textViewDefaultHeight) { 
    highlightsPixelsAdded = newTextViewHeight - textViewDefaultHeight; 
    viewPixelsToBeAdded += highlightsPixelsAdded; 
    txtTentsHead.frame = CGRectOffset(txtTentsHead.frame, 0, highlightsPixelsAdded); 
    txtTents.frame = CGRectOffset(txtTents.frame, 0, highlightsPixelsAdded); 
    txtNotesHead.frame = CGRectOffset(txtNotesHead.frame, 0, highlightsPixelsAdded); 
    txtNotes.frame = CGRectOffset(txtNotes.frame, 0, highlightsPixelsAdded); 
    txtDirectionsHead.frame = CGRectOffset(txtDirectionsHead.frame, 0, highlightsPixelsAdded); 
    txtDirections.frame = CGRectOffset(txtDirections.frame, 0, highlightsPixelsAdded); 
    txtRentalsHead.frame = CGRectOffset(txtRentalsHead.frame, 0, highlightsPixelsAdded); 
    txtRentals.frame = CGRectOffset(txtRentals.frame, 0, highlightsPixelsAdded); 


} else if (newTextViewHeight < textViewDefaultHeight) { 
    highlightsPixelsRemoved = textViewDefaultHeight - newTextViewHeight; 
    viewPixelsToBeRemoved += highlightsPixelsRemoved; 
    txtTentsHead.frame = CGRectOffset(txtTentsHead.frame, 0, -highlightsPixelsRemoved); 
    txtTents.frame = CGRectOffset(txtTents.frame, 0, -highlightsPixelsRemoved); 
    txtNotesHead.frame = CGRectOffset(txtNotesHead.frame, 0, -highlightsPixelsRemoved); 
    txtNotes.frame = CGRectOffset(txtNotes.frame, 0, -highlightsPixelsRemoved); 
    txtDirectionsHead.frame = CGRectOffset(txtDirectionsHead.frame, 0, -highlightsPixelsRemoved); 
    txtDirections.frame = CGRectOffset(txtDirections.frame, 0, -highlightsPixelsRemoved); 
    txtRentalsHead.frame = CGRectOffset(txtRentalsHead.frame, 0, -highlightsPixelsRemoved); 
    txtRentals.frame = CGRectOffset(txtRentals.frame, 0, -highlightsPixelsRemoved); 

} 


//----------------------------------------------------------------------------  

txtTents.text = _Campground.tents; 

//----------------------------------------------------------------------------  

txtNotes.text = _Campground.notes; 
[self fitFrameToContent:txtNotes]; 
newTextViewHeight = txtNotes.contentSize.height; 
if (newTextViewHeight > textViewDefaultHeight) { 
    notesPixelsAdded = newTextViewHeight - textViewDefaultHeight; 
    viewPixelsToBeAdded += notesPixelsAdded; 

    txtDirectionsHead.frame = CGRectOffset(txtDirectionsHead.frame, 0, notesPixelsAdded); 
    txtDirections.frame = CGRectOffset(txtDirections.frame, 0, notesPixelsAdded); 
    txtRentalsHead.frame = CGRectOffset(txtRentalsHead.frame, 0, notesPixelsAdded); 
    txtRentals.frame = CGRectOffset(txtRentals.frame, 0, notesPixelsAdded); 


} else if (newTextViewHeight < textViewDefaultHeight) { 
    notesPixelsRemoved = textViewDefaultHeight - newTextViewHeight; 
    viewPixelsToBeRemoved += notesPixelsRemoved; 

    txtDirectionsHead.frame = CGRectOffset(txtDirectionsHead.frame, 0, -notesPixelsRemoved); 
    txtDirections.frame = CGRectOffset(txtDirections.frame, 0, -notesPixelsRemoved); 
    txtRentalsHead.frame = CGRectOffset(txtRentalsHead.frame, 0, -notesPixelsRemoved); 
    txtRentals.frame = CGRectOffset(txtRentals.frame, 0, -notesPixelsRemoved); 

} 


//----------------------------------------------------------------------------  

txtDirections.text = _Campground.directions; 
[self fitFrameToContent:txtDirections]; 
newTextViewHeight = txtDirections.contentSize.height; 
if (newTextViewHeight > textViewDefaultHeight) { 
    directionsPixelsAdded = newTextViewHeight - textViewDefaultHeight; 
    viewPixelsToBeAdded += directionsPixelsAdded; 

    txtRentalsHead.frame = CGRectOffset(txtRentalsHead.frame, 0, directionsPixelsAdded); 
    txtRentals.frame = CGRectOffset(txtRentals.frame, 0, directionsPixelsAdded); 


} else if (newTextViewHeight < textViewDefaultHeight) { 
    directionsPixelsRemoved = textViewDefaultHeight - newTextViewHeight; 
    viewPixelsToBeRemoved += directionsPixelsRemoved; 

    txtRentalsHead.frame = CGRectOffset(txtRentalsHead.frame, 0, -directionsPixelsRemoved); 
    txtRentals.frame = CGRectOffset(txtRentals.frame, 0, -directionsPixelsRemoved); 

} 

//----------------------------------------------------------------------------  

txtRentals.text = _Campground.rentals; 
[self fitFrameToContent:txtRentals]; 
newTextViewHeight = txtRentals.contentSize.height; 
if (newTextViewHeight > textViewDefaultHeight) { 
    rentalsPixelsAdded = newTextViewHeight - textViewDefaultHeight; 
    viewPixelsToBeAdded += rentalsPixelsAdded; 


} else if (newTextViewHeight < textViewDefaultHeight) { 
    rentalsPixelsRemoved = textViewDefaultHeight - newTextViewHeight; 
    viewPixelsToBeRemoved += rentalsPixelsRemoved; 

} 

viewHeight += viewPixelsToBeAdded; 
viewHeight -= viewPixelsToBeRemoved; 
detailsView.frame = CGRectMake(0, 20, 320, viewHeight); 
scrollView.frame = CGRectMake(0, 20, 320, viewHeight); 
} 
+0

私たちは文脈を持つように、いくつかのコードを投稿してください。また、(これは関連する問題ではありませんが)、UIKitのサイズは通常int値ではなくCGFloatを使用します。また、「スクロールを止める」とはどういう意味ですか?現在のスクロールアニメーションが停止している、またはスクロールがそれ以降は機能しないことを意味しますか? – fzwo

+0

スクロールを停止すると、480pxを超えるものは見えません。表示されるのは、iPhoneのデフォルトサイズでポップアップするものだけです。それ以下のものはスクロールしません。私はpopulateLabelsメソッドを投稿しました。私はあなたが必要とする何かを含めることができます。 – tallybear

+0

ビュー自体が実際にサイズ変更されています。背景色を付けてチェックしました。これは、サイズを変更しないscrollViewです。私はscrollViewを設定して、一度にdetailsViewを設定しました。そうでなければスクロールしません。今私はビュー自体をdetailsViewに設定し、魔法のように...まだスクロールしています。これで、scrollViewのサイズを正しく変更する方法を理解する必要があります。 – tallybear

答えて

1

scrollviewには、画面上での大きさ(および場所)を決定するframeとスクロールする距離を決定するcontentSizeという2つのサイズがあります。

contentSizeframe.sizeと同じか小さい場合、scrollViewはスクロールされません(スクロールするものがないため)。

通常、スクロールビューのcontentSizeは、配置したビューのサイズに設定することをお勧めします。

のサイズが1000x1000ポイントであるとします。そのframeはおそらくCGRectMake(0, 0, 1000, 1000)になります。あなたのScrollViewが縦向きのiPhone上で全画面表示されているので、フレームはCGRectMake(0, 0, 320, 480)です。 contentSizeCGSizeMake(1000, 1000)に設定すると、すべての画像をスクロールすることができます。 contentSizeを320 x 480の長方形にすると、まったくスクロールしません。 contentSizeを2000x2000に設定すると、画像よりもスクロールできるようになります。

2

あなたはUIViewのとUIScrollViewの両方で、画面よりもはるかに大きい同じフレームを設定しているように聞こえますか?したがって、スクロールビューはスクロール表示されません。そのスクロール表示は、そのスクロールビュー内のビューと同じサイズです。スクロールするだけで何も表示されません。

おそらく、スクロールビューのフレームをそのままにしておき、内容のサイズにかかわらずスクロールビューの画面サイズを同じにして、contentSizeプロパティを設定します。同様に、ビューフレームはその親に対して相対的なので、スクロールビュー内のビューのy座標として0を渡したいと思うでしょう。

+0

このような仕組みになっています。それは再びスクロールしていますが、私の見解は私が必要とするところまで縮小していません。私は、そのビューをコンテンツがどこで止まるかにまで縮小する方法を理解できません。 – tallybear

+0

scrollViewをビュー内に置いて、スクロールビュー内にすべてのオブジェクトを配置する必要がありますか?私は今それを持っている方法... scrollViewはトップです。その中には実際の見方があります。ビュー内にオブジェクト(textViews、labels、buttonsなど)があります。 – tallybear

+0

スクロールするものはスクロールビューの子である必要があります。残念ながら、それは十分にスマートではないし、スクロールビューが子どもに基づいて独自のcontentSizeを把握するオプションがないので、ちょっとしたナッジを与える必要があります。 – Tommy

関連する問題