在UIViewController
中,我有一個UIScrollView
,它佔用了屏幕的一半。此UIScrollView
包含UIView
的集合。在某些特定事件(例如滑動)上,我希望我的UIScrollView
能夠全屏動畫,我該如何實現這一行爲?iOS - UIScrollView從一半到全屏
回答
嘗試......
// adding swipe gesture to your scrollview
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
// Set swipe direction.
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[scrollview addGestureRecognizer:swipeLeft];
// add gesture action method
- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe {
// if you are having only one swipe gesture, you no need to add the below condition. you can add the code inside the condition
if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"Left Swipe");
scrollView.contentSize = self.view.frame;
scrollView.frame = self.view.frame;
}
}
嘗試使用這種方法的事件,並設置:
scrollView.contentSize = CGSizeMake(847, 800); // change on basis of your requirement
對於動畫滾動視圖:
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; // animate at constant velocity to new offset
設定內容偏移不會改變'UIScrollView' – bohanl
的大小是的..如果你仔細看看我已經提到contentSize設置和動畫我已經說contentOffset –
從@ RAJA的回答和引用略有改善:
[UIView beginAnimations:@"whatever" context:nil];
scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height * <count of subviews>);
scrollView.frame = self.view.frame;
[UIView commitAnimations];
我只是延長了第一個答案,如果你想動畫上述過程,就可以實現通過追加下面的代碼:
- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe
{
if (swipe.direction == UISwipeGestureRecognizerDirectionLeft)
{
[UIView animateWithDuration:0.15f // set duration for your animation here
animations:^{
scrollView.contentSize = self.view.frame;
scrollView.frame = self.view.frame;
}
completion:^(BOOL finished){
NSLog(@"completion block");
}];
}
}
我只能通過使用NSLayoutAttributeHeight改變它的高度來使用NSLayoutConstraint。我知道這個解決方案可能不是典型的,但你是否看到任何缺點? – bohanl
- 1. 從UIScrollView中將UITableView縮放到全屏
- 2. iOS UITableView在UIScrollView全高度
- 3. iOS版全屏iAd
- 4. 全屏UIScrollView無法正常工作
- 5. 將uiscrollview子視圖調整爲全屏
- 6. 如何在全屏UIScrollView中對齊UIImageView?
- 7. UIScrollView開始一半的內容
- 8. ios幫助屏幕半透明覆蓋
- 9. iOS彈力圖像到全屏
- 10. 找到一個峯的半峯全寬
- 11. 分割屏幕一半CSS
- 12. UiScrollView IOS
- 13. 從uiscrollview更改第一響應者到uitableview中觸摸iOS iphone
- 14. 半屏的div不會擴展到完全寬度
- 15. iOS的 - 在一個UIScrollView
- 16. 全屏相機在IOS
- 17. iOS - 強制全屏視頻
- 18. 全屏iOS分享擴展
- 19. iOS 7 InteractivePopGesture全屏UICollectionView
- 20. 防止iOS上的全屏
- 21. 擬合的ImageView屏幕高度和全屏幕寬度的一半
- 22. 全屏從javascript
- 23. 從全屏切換到不全屏幕彈出/滑動
- 24. 半屏TabHost
- 25. 半屏活動
- 26. 在Android上升級到PhoneGap 1.1 - 現在屏幕的一半是一半黑色,一半白色
- 27. 位置圖像一半在屏幕邊界內,一半在外
- 28. 從三分之一列到一半colums
- 29. iOS UIScrollView requireGestureToFail
- 30. UIView iOS UIScrollView
不工作,我的'UIScrollView'根本不改變它的大小 – bohanl
我可以知道你如何設置滾動視圖。你是用xib還是以編程方式。如果可能的話,你可以分享你的代碼片段 – RAJA
相同的代碼,它爲我工作..我能夠重新大小滾動查看滑動..你可以請檢查它。 – RAJA