13 uiscrollview uiview ios swift
在ScrollView中的UIView,SegmentedController和UIContainerView或类似的东西?
在我的故事板中,我有一个VC包含顶部的UIView,中间的分段控制器和底部的2个ContainerViewControllers,嵌入了新的VC的segue.
在新的VC中我有一个TableView和一个CollectionView(例如,Instagram的个人资料).
我的问题是我需要SegmentedController和UIView使用ContainerView(TableView/CollectionView)滚动,此时只有ContainerView部分滚动并且上面的部分是固定的.
现在我猜我可能需要将所有内容放入UIScrollView中,所以我尝试了并正确放置了所有的成本.但是当它在Swift文件中进行配置时,我现在只是如何设置滚动的高度,但是我需要的高度显然可以变化并且不是固定的高度!
如果有人可以在这里帮助我,这将是非常棒的,或者可能指向我这里已经问过的类似问题?我已经看了,但遗憾的是没找到任何东西!
下面的图片基本上解释了我所追求的内容,如果上面我不是很清楚..
这是一个你可以看到的例子:https://github.com/Jackksun/ScrollIssue
小智 2
据我了解,您想让滚动视图接收其边界之外的触摸。您可以通过在实际接收触摸的视图上重写 hitTest:withEvent: 方法来实现此目的。
这是我在项目中所做的示例。我对 UIView 进行了子类化,并将其接收到的所有触摸重定向到特定视图。在您的情况下,您将重定向所有触摸到滚动视图。
.h file:
@import UIKit.UIView;
/*!
@class TouchableView
@abstract Touchable view.
*/
@interface TouchableView : UIView
/*!
@property viewToReceiveTouches
@abstract View that receives touches instead of a given view.
*/
@property (nonatomic, weak) IBOutlet UIView *viewToReceiveTouches;
@end
.m file:
@import UIKit.UIButton;
@import UIKit.UITableView;
@import UIKit.UITextField;
#import "TouchableView.h"
@implementation TouchableView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if ( [self shouldViewReceiveTouch:self inPoint:point] )
{
return [super hitTest:point withEvent:event];
}
else if ( CGRectContainsPoint(self.bounds, point) && self.isUserInteractionEnabled )
{
return self.viewToReceiveTouches;
}
return nil;
}
- (BOOL)shouldViewReceiveTouch:(UIView *)view inPoint:(CGPoint)point
{
if ( !CGRectContainsPoint(view.bounds, point) || !view.isUserInteractionEnabled )
{
return NO;
}
if ( [view isKindOfClass:[UIButton class]] ||
[view isKindOfClass:[UITextField class]] ||
[view isKindOfClass:[UITableViewCell class]] ||
[view isKindOfClass:[UITableView class]] )
{
return YES;
}
for ( UIView *subview in view.subviews )
{
if ( [self shouldViewReceiveTouch:subview inPoint:[view convertPoint:point toView:subview]] )
{
return YES;
}
}
return NO;
}
@end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1777 次 |
| 最近记录: |