我在我的主视图,可同时接收应用程序touchesBegan和touchesMoved,因此,需要在单手指触摸,并拖动.我想实现一个UIScrollView,我有它的工作,但它覆盖了拖动,因此我的contentView永远不会收到它们.我想实现一个UIScrollview,其中双指拖动指示滚动,并且单指拖动事件被传递到我的内容视图,因此它正常执行.我需要创建自己的子类UIScrollView吗?
这是我appDelegate实现的代码UIScrollView.
@implementation MusicGridAppDelegate
@synthesize window;
@synthesize viewController;
@synthesize scrollView;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
//[application setStatusBarHidden:YES animated:NO];
//[window addSubview:viewController.view];
scrollView.contentSize = CGSizeMake(720, 480);
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.showsVerticalScrollIndicator = YES;
scrollView.delegate = self;
[scrollView addSubview:viewController.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[viewController release];
[scrollView release];
[window release];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个具有多个视图的页面视图控制器.我想要一个使用UIPageViewController的简单代码示例.
在UIScrollView中进行分页是一个很棒的功能,我需要的是将分页设置为较小的距离,例如我希望我的UIScrollView页面的大小小于UIScrollView的帧宽.谢谢
我将浏览iPhone WWDC 2010 - 104 PhotoScroller App的示例代码.它与我的项目相关图像(PDF页面图像)工作得很好
但我正在努力检测PhotoScroller应用程序中的触摸.使用多次触摸的缩放由ScrollVoiew处理.现在我想要双击放大/缩小照片.在TilingView类中调用Touchesbegan方法.然后我使用[super touchesbegan:withevent:],现在触摸在ImageScrollView类中.
如何在PhotoViewController中获取这些触摸事件.如何实现放大和缩小触摸?
任何人都可以帮助这个Regard?
我有一个垂直滚动UIScrollView.我还想在其上处理水平平移,同时允许默认的垂直滚动行为.我UIView在滚动视图上放置了一个透明图,并为其添加了一个平移手势识别器.这样我可以很好地获得平底锅,但滚动视图不会接收任何手势.
我已经实现了以下UIPanGestureRecognizerDelegate方法,希望仅将我的手势识别器限制为水平平底锅,但这没有帮助:
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
// Only accept horizontal pans here.
// Leave the vertical pans for scrolling the content.
CGPoint translation = [gestureRecognizer translationInView:self.view];
BOOL isHorizontalPan = (fabsf(translation.x) > fabsf(translation.y));
return isHorizontalPan;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return (otherGestureRecognizer == _scrollView.panGestureRecognizer);
}
Run Code Online (Sandbox Code Playgroud) uiscrollview uigesturerecognizer ios ios5 uipangesturerecognizer
在这里,我有一个页面控件,它工作正常,但点击它不会改变页面,所以请帮助改变页面的功能:
- (void)viewDidLoad {
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 420)];
scrollView.delegate = self;
[self.scrollView setBackgroundColor:[UIColor whiteColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
[scrollView setShowsHorizontalScrollIndicator:NO];
scrollView.pagingEnabled = YES;
[self.view addSubview:scrollView];
pageControl=[[UIPageControl alloc]initWithFrame:CGRectMake(0, 420, 320, 40)];
[pageControl addTarget:self action:@selector(changepage:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:pageControl];
UIView *blueView = [[UIView alloc] init];
blueView.frame = CGRectMake(0, 0, 640, 480);
blueView.backgroundColor = [UIColor whiteColor];
[scrollView addSubview:blueView];
self.pageControl.numberOfPages = 2;
[scrollView setContentSize:CGSizeMake(640, 0)];
}
-(void)changepage:(id)sender
{
int page = pageControl.currentPage;
if (page < 0)
return; …Run Code Online (Sandbox Code Playgroud) 我有一个相当简单的视图配置:
一UIViewController,与孩子UIScrollView和UIImageView在此UIScrollView.我设置的UIImageView高度足以突破可见区域(即更高1024pt),并将Bottom space to superviewmy 的约束设置UIImageView为固定的正值(20例如).

整个设置按预期工作,图像在其父级中滚动很好.除非滚动视图(如果滚动到视图底部,效果更明显),然后消失,再次出现(您切换到另一个视图并返回)滚动值将恢复,但内容为滚动视图移动到其父视图的外部顶部.
这不是一个简单的解释,我会尝试绘制它:

如果你想测试/查看源(或故事板,我没有编辑一行代码).我在我的github上放了一个小小的演示:https://github.com/guillaume-algis/iOSAutoLayoutScrollView
我确实阅读了iOS 6更新日志和关于这个特定主题的解释,并认为这是第二个选项(纯自动布局)的正确实现,但在这种情况下,为什么UIScrollView表现如此不规律?我错过了什么吗?
编辑:这是与#12580434 uiscrollview-autolayout-issue完全相同的问题.答案只是解决方法,因为任何人都找到了解决这个问题的正确方法,或者这是一个iOS错误?
编辑2:我找到了另一种解决方法,它将滚动位置保持在用户离开的相同状态(这是对12580434接受的答案的改进):
@interface GAViewController ()
@property CGPoint tempContentOffset;
@end
@implementation GAViewController
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.tempContentOffset = self.mainScrollView.contentOffset;
self.scrollView.contentOffset = CGPointZero;
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.scrollView.contentOffset = self.tempContentOffset;
}
Run Code Online (Sandbox Code Playgroud)
这基本上保存了偏移量viewWillAppear,将其重置为原点,然后恢复该值viewDidAppear.问题似乎发生在这两个调用之间,但我无法找到它的起源.
使用自动布局约束我遇到了UIScrollView的麻烦.我有以下视图层次结构,通过IB设置约束:
- ScrollView (leading, trailing, bottom and top spaces to superview)
-- ContainerView (leading, trailing, bottom and top spaces to superview)
--- ViewA (full width, top of superview)
--- ViewB (full width, below ViewA)
--- Button (full width, below ViewB)
Run Code Online (Sandbox Code Playgroud)
ViewA和ViewB的初始高度为200点,但可以通过单击将其垂直扩展到400点的高度.ViewA和ViewB通过更新其高度约束(从200到400)进行扩展.这是相应的片段:
if(self.contentVisible) {
heightConstraint.constant -= ContentHeight;
// + additional View's internal constraints update to hide additional content
self.contentVisible = NO;
} else {
heightConstraint.constant += ContentHeight;
// + additional View's internal constraints update to show additional content
self.contentVisible = YES; …Run Code Online (Sandbox Code Playgroud) 我正在制作一个需要知道用户何时滚动的Mac应用程序NSScrollView,但是,我找不到任何类似的方法UIScrollView,它具有以下委托方法:
– scrollViewDidScroll:
– scrollViewWillBeginDragging:
– scrollViewDidEndDragging:willDecelerate:
– scrollViewShouldScrollToTop:
– scrollViewDidScrollToTop:
– scrollViewWillBeginDecelerating:
– scrollViewDidEndDecelerating:
Run Code Online (Sandbox Code Playgroud)
我可以为App Kit使用类似的委托方法吗?提前致谢.
凯.
我UIScrollView添加了一个单击手势识别器来显示/隐藏一些UI叠加使用:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[scrollView addGestureRecognizer:singleTap];
Run Code Online (Sandbox Code Playgroud)
和:
- (void)handleTap:(UITapGestureRecognizer *)sender {
// report click to UI changer
}
Run Code Online (Sandbox Code Playgroud)
我在底部添加了一个简单的表格视图UIScrollView.一切正常(水平和垂直滚动)但问题是点击仅由手势识别器(上图)识别,而不是由简单的表格视图识别.如果我删除注册手势监听器的行,一切正常,表视图会通知自己.
这就好像手势识别器功能"吃掉"表视图上的点击事件并且不向下传播它们.
任何帮助表示赞赏
uiscrollview ×10
ios ×6
objective-c ×5
iphone ×4
autolayout ×2
cocoa ×1
ios5 ×1
ipad ×1
macos ×1
nsscrollview ×1
pagination ×1
swift ×1
touchesbegan ×1
uitouch ×1
wwdc ×1