問題時:看到UIScrollView的背景的大面積放大的和向下平移
我遇到的問題是,當我放大到我的UIScrollView(啓用了分頁),然後我平移(滾動? )向下 - 我可以很好地拖過我的視圖並查看scrollview背景的大部分區域。我放大的越遠,UIScrollView的背景就越多。 (我已經將scrollview的背景設置爲綠色,所以我可以告訴我在看什麼)。
不知道爲什麼背景區域暴露如此...?
我已經玩過在各個位置設置滾動視圖的框架大小,邊界大小,內容大小等無濟於事。
不幸的是我不能發佈的截圖發生了什麼,由於是一個新的用戶:(
進一步瞭解詳細:
我的應用程序的主視圖包含一個全屏幕的大小UIScrollView中填充了一系列的UIView子視圖這些子視圖通過在for循環中創建nib名稱添加到滾動視圖中,然後使用loadNibNamed方法檢索它們以創建&添加UIView
每個UIView都是在IB中設計的d包含以下內容:一個UIImageView,其圖像屬性設置爲.jpg圖像,另一個較小的UIScrollView,以及一個透明的UIView,位於包含一堆定製UIButton的imageview之上。
當我填充我的scrollView後,我設置它的一些屬性,如contentSize,pagingEnabled,min & maxZoomScale等。&然後將它的委託設置爲self(MainViewController)。
MainViewController的相關方法:
@implementation MainViewController_iPhone
@synthesize scrollView, loadedNibView;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[self loadNibs];
[self initializeOrientation];
}
-(void) loadNibs {
currentPage = 0;
for (int i = 0; i < NUM_VIEWS; i++) {
loadedNibView = [self getNibView:i]; //load the UIView from the associated nib file
loadedNibView.tag = i; //used later to retrieve view for current page
[scrollView addSubview:loadedNibView];
}
//Set the content size to sum of the widths of the all UIViews
scrollView.contentSize = CGSizeMake(self.view.frame.size.width * NUM_VIEWS, self.view.frame.size.height);
scrollView.pagingEnabled = YES;
scrollView.bounces = YES;
scrollView.clipsToBounds = YES;
//scrollView.alwaysBounceVertical = YES;
//zoom features
scrollView.maximumZoomScale = 5.0;
scrollView.minimumZoomScale = 1;
scrollView.delegate = self;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)myScrollView {
return [myScrollView viewWithTag:(currentPage)];
}
- (void)scrollViewDidScroll:(UIScrollView *)myScrollView {
CGFloat pageWidth = myScrollView.frame.size.width;
currentPage = floor((myScrollView.contentOffset.x - pageWidth/2)/pageWidth) + 1;
}
- (void)scrollViewDidZoom:(UIScrollView *)myScrollView {
}
- (void)scrollViewWillBeginZooming:(UIScrollView *)myScrollView withView:(UIView *)view
{
//zooming & paging do not work well together; disable paging while we're zooming
myScrollView.pagingEnabled = NO;
}
- (void)scrollViewDidEndZooming:(UIScrollView *)myScrollView withView:(UIView *)view atScale:(float)scale
{
if(scale == 1) //if we're zoomed entirely back out
{
//re-enable paging & reset the content size
myScrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(self.view.frame.size.width * NUM_VIEWS, self.view.frame.size.height); //without this line, can no longer page through scrollview after zooming
}
}
@end
而且它的.H:
@interface MainViewController_iPhone : MainViewController <UIScrollViewDelegate> {
IBOutlet UIScrollView *scrollView; //The main ScrollView that scrolls between pages of different images to search
UIView *loadedNibView; //The UIView that we load from it's corresponding nib (i.e. IMG1_iPhone.xib)
int currentPage;
}
//methods
-(void) loadNibs;
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)myScrollView;
- (void)scrollViewWillBeginZooming:(UIScrollView *)myScrollView withView:(UIView *)view;
- (void)scrollViewDidEndZooming:(UIScrollView *)myScrollView withView:(UIView *)view atScale:(float)scale;
- (void)scrollViewDidZoom:(UIScrollView *)myScrollView;
- (void)scrollViewDidScroll:(UIScrollView *)myScrollView;
//properties
@property (nonatomic, retain) UIScrollView *scrollView;
@property (nonatomic, retain) UIView *loadedNibView;
@end
任何意見/建議將不勝感激...謝謝!