[英]UIScrollView will not zoom
我有一個子類的UIView
,我可以滾動但不能縮放。 我正在使用自動布局,因此想知道IOS6中是否有任何更改。 特別是何時實現了scrollViewWillBeginZooming
和scrollViewDidEndZooming
方法。 我的代碼看起來像
- (void)viewDidLoad
{
[super viewDidLoad];
self.ringSet2 = [[RingView alloc] initWithFrame:CGRectMake(0, 0, 800, 800)];
[self.ringSet2 setDefaults];
/// ... more setup for other views but only ringSet2 is scrolled.
self.scrollview1.delegate=self;
self.scrollview1.scrollEnabled=YES;
self.scrollview1.contentSize=self.ringSet2.bounds.size
self.scrollview1.minimumZoomScale=0.2;
self.scrollview1.maximumZoomScale=5.0;
self.ringSet2.userInteractionEnabled=YES;
// ... needed elsewhere so other views can pick up their dimensionts
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
/// ... code for additional views
[self.scrollview1 zoomToRect:CGRectMake(0, 0, 200, 200) animated:YES];
[self.scrollview1 addSubview:self.ringSet2];
}
與
-(UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return self.ringSet2;
}
和scrollViewWillBeginZooming
等實現只是為了跟蹤正在發生的事情。 有趣的是, viewForZoomingInScrollView
似乎只被調用一次, scrollViewDidEndZooming
的縮放值僅小於1,但從未調用過scrollViewWillBeginZooming
。 定義了屬性ringSet2
@property (strong, nonatomic) IBOutlet RingView *ringSet2;
因為如果將視圖定義為弱視圖,則視圖不會出現。
對此表示歉意。 答案確實很愚蠢。 我目前正在模擬器上的IOS 6.0下進行開發,而我的手機仍在IOS 5上。該模擬器可讓您模擬捏,但只能以屏幕的中心為中心。 但是,scrollview僅在它也位於中心時才接收到此信號,而在我的初始構建中不是這種情況。 將滾動視圖的矩形移到中間可以解決此問題。 您不會在真實設備上進行此錯誤測試。 這樣代碼就可以了。 失去了3或4個晚上,這使我無法擺脫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.