如何强制进行UIScrollView分页和滚动仅在给定时刻垂直或水平移动?
我的理解是directionalLockEnabled属性应该实现这一点,但是对角线滑动仍然导致视图对角滚动而不是将运动限制到单个轴.
编辑:为了更清楚,我想让用户水平或垂直滚动,但不能同时滚动.
我有一个滚动视图,它是屏幕的宽度,但只有约70像素高.它包含许多50 x 50图标(周围有空格),我希望用户可以选择.但我总是希望滚动视图以分页的方式运行,始终在正确的中心以图标停止.
如果图标是屏幕的宽度,这不会是一个问题,因为UIScrollView的分页会处理它.但是因为我的小图标远小于内容大小,所以它不起作用.
我之前在应用程序调用AllRecipes中看到过这种行为.我只是不知道该怎么做.
有关如何在每个图标大小的基础上进行分页工作的任何想法?
我正在使用SDK 10.7作为部署目标的Mac OS X应用程序.NSScrollView包含图像缩略图的水平列表.位于ScrollView中心的缩略图表示所选图像,该图像以完整大小显示在ScrollView下方.这与Finder Cover-Flow非常相似,除了我的应用程序中的图像不会流动但只是向外滚动.
我想限制滚动仅在缩略图正好位于中心时停止.NSView方法adjustScroll:没有解决方案.这将禁用"平滑"滚动并让ScrollView从一个缩略图跳转到下一个缩略图.
我需要某种动作/回调告诉我ScrollView完成了滚动.我可以检查位置是否正常(如果缩略图在中间)或向后/向前滚动到最近的缩略图.但NSScrollView不提供这样的回调.
我试着观察ScrollViews contenView框架的变化.交替帧改变我启动计时器.如果计时器在启动之前没有重新启动,我认为滚动停止了.这不是很好.如果滚动仅在短时间内停止(例如,因为手指被移动以进行另一次轻扫手势),则下一次滚动会干扰位置的校正.
在iOS下使用UIScrollView可以毫无问题地解决此任务.NSScrollView的类似分页功能将是一个完美的解决方案.
有谁知道如何解决这个问题?
非常感谢你!
我正在开发一个有ViewPager菜单的应用程序.每个fragment有一堆的可以是孩子的意见ListView,ScrollView,LinearLayout,等...一本fragments有一个设置按钮,切换一个设置面板(LinearLayout带包装)ScrollView和一些LinearLayout(按钮),并SeekBar为孩子的.此设置面板使用向上或向下滑动动画(当被关闭时)动画,当它可见时我禁用ViewPager分页:
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!pagingEnabled && event.getAction() == MotionEvent.ACTION_MOVE) {
return true;
}
return super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (!pagingEnabled && event.getAction() == MotionEvent.ACTION_MOVE) {
return true;
}
return super.onInterceptTouchEvent(event);
}
public boolean isPagingEnabled() {
return pagingEnabled;
}
public void setPagingEnabled(boolean pagingEnabled) {
this.pagingEnabled = pagingEnabled; …Run Code Online (Sandbox Code Playgroud) 我正在使用一个UIScrollView用于分页的三个不同的UIViewControllers.寻呼机初始化为从头开始显示第1页.因此,用户可以从头开始向左或向右滑动.当我从中视图控制器呈现模态视图控制器时UIScrollView,在呈现的视图控制器的动画期间临时滚动到第一页.当我关闭模态视图控制器时,一切都恢复正常,并UIScrollView显示中央视图控制器.
我期望(并希望)UIScrollView在动画期间保持它的位置.
这不是导致崩溃或其他什么的技术错误,它只是丑陋.
以前有过这样的人吗?知道怎么解决吗?
paging cocoa-touch uiscrollview presentmodalviewcontroller scroll-paging
我想添加一个带分页的UIScrollView来浏览我现有视图控制器的不同视图,这是我的应用程序的根视图.我还有标签栏和导航栏控制器.我是否可以向此视图控制器添加滚动视图以完成我想要的内容,如果是这样,有人可以指出我正确的方向如何去做吗?
这是我的视图控制器.
#import "KFBViewController.h"
#import "ListViewController.h"
#import "ActionAlertsViewController.h"
#import "MarketUpdatesViewController.h"
#import "AgStoriesViewController.h"
#import "KFBNewsViewController.h"
#import "MemberBenefits.h"
#import "SocialNetworks.h"
#import "WebViewController.h"
#import "YouTubeView.h"
#import "KFBFlickrViewController.h"
#import "RSFM.h"
#import "UAPush.h"
#import "TUSafariActivity.h"
@interface KFBViewController ()
{
}
@end
@implementation KFBViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
self.title = NSLocalizedString(@"Home", @"Home");
self.tabBarItem.image = [UIImage imageNamed:@"home"];
self.navigationController.delegate = self;
}
return self;
}
- (void) showMenu
{
NSURL *urlToShare = [NSURL URLWithString:@"https://itunes.apple.com/us/app/kentucky-farm-bureau/id580530986?mt=8"];
NSArray *activityItems = @[urlToShare]; …Run Code Online (Sandbox Code Playgroud) 我已经customFlowLayout在我的 iOS 应用程序中实现了。我已经将targetContentOffsetForProposedContentOffset:withScrollingVelocitywith subclassing进行了子类化UICollectionViewFlowLayout。现在我的问题是当用户滚动collectionview它必须只滚动到下一个索引。现在它随机滚动。
所以任何人都知道如何使滚动限制为每个滚动只有一个项目。
以下是我的代码。
#pragma mark - UICollectionViewLayout (UISubclassingHooks)
- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity {
CGSize collectionViewSize = self.collectionView.bounds.size;
CGFloat proposedContentOffsetCenterX = proposedContentOffset.x + collectionViewSize.width / 2;
CGRect proposedRect = CGRectMake(proposedContentOffset.x, 0, collectionViewSize.width, collectionViewSize.height);
UICollectionViewLayoutAttributes *candidateAttributes;
for (UICollectionViewLayoutAttributes *attributes in [self layoutAttributesForElementsInRect:proposedRect]) {
if (attributes.representedElementCategory != UICollectionElementCategoryCell) continue;
if (!candidateAttributes) {
candidateAttributes = attributes;
continue;
}
if (fabs(attributes.center.x - proposedContentOffsetCenterX) < fabs(candidateAttributes.center.x - proposedContentOffsetCenterX)) {
candidateAttributes = attributes;
}
}
proposedContentOffset.x = …Run Code Online (Sandbox Code Playgroud) 我追求的效果:只有在滚动时才可见的图像之间的间距(如照片应用程序)。
许多旧的 obj-c 答案建议将滚动视图的边界扩展到屏幕外以使其页面更远,并使这个屏幕外空间成为图像之间的间隙。
pagingEnabled 的文档指出:
如果此属性的值为 YES,则当用户滚动时,滚动视图将在滚动视图边界的倍数处停止。
因此,在尝试更改倍数值时,我扩展了 scrollView 的宽度,并启用了左分页。然而,我没有实现页面超越差距的答案 - 他们总是把它留在视野中:
那么如果滚动宽度更长,为什么它不分页合适的距离呢?
let gapMargin = CGFloat(20)
scrollView.frame = CGRect(x: 0, y: 0, width: view.frame.width + gapMargin, height: view.frame.height)
let exdScrollWidth = scrollView.frame.width
//1
let imageView1 = UIImageView()
imageView1.backgroundColor = UIColor.green
imageView1.frame = CGRect(x: 0, y: 0, width: exdScrollWidth - gapMargin, height: scrollView.bounds.size.height)
//2
let imageView2 = UIImageView()
imageView2.backgroundColor = UIColor.yellow
imageView2.frame = CGRect(x: exdScrollWidth, y: 0, width: exdScrollWidth - gapMargin, height: scrollView.bounds.size.height)
//3
let imageView3 = UIImageView()
imageView3.backgroundColor …Run Code Online (Sandbox Code Playgroud) 我想重新创建我下面的图片的应用程序的布局.顶部有一个导航栏,中间有分页内容.我已经查看了几种如何页面内容的方法,包括UIScrollViews,UIPageControl和PageViewControllers,但我似乎无法重新创建这种布局.我找到的大多数教程也没有为iOS7更新.所有输入都非常感谢.
图片:

如果我想在Apple Watch上设计许多内容,然后超出屏幕,可以滚动或分页吗?
scroll-paging ×10
uiscrollview ×6
ios ×5
objective-c ×2
android ×1
cocoa-touch ×1
ios7 ×1
macos ×1
nsscrollview ×1
paging ×1
scroll ×1
swift ×1
watchkit ×1