我有一个UIScrollView动态添加到主视图中,我用小UIView对象填充它.我将它的contentSize设置为大于设备分辨率的东西,但在我改变设备的方向之前我无法滚动它.
如何在方向改变之前滚动?
后期编辑:
我意识到问题来自我正在添加的某些子视图,更具体地说是为这些子视图添加一些约束:
这是我添加子视图的代码(该方法被调用大约10-20次):
-(void) addShelve:(NSInteger) index
{
FSShelf *shelf = [[FSShelf alloc] initWithFrame:CGRectMake(0, index * [FSConstants getShelfVerticalDistance], 0, 0)];
[shelves addObject:shelf];
[shelfView addSubview:shelf];
[shelf addShelfConstraints];
}
Run Code Online (Sandbox Code Playgroud)
FSShelf是UIView的子类,shelfView是我的UIScrollView的子类.
以下是在以下位置添加的约束addShelfContraints:
[self.superview addConstraint:[FSUtils getWidthConstraintFor:self.superview with:self constant: -2 * ([FSConstants getShelveMargin])]];
[self addConstraint:[FSUtils getSelfHeightConstraintFor:self constant:30]];
[self.superview addConstraint:[FSUtils getCenterXConstraintFor:self.superview with:self constant:0]];
Run Code Online (Sandbox Code Playgroud)
FSUtils类中用于添加约束的方法:
+ (NSLayoutConstraint *)getSelfHeightConstraintFor:(UIView *)view constant:(CGFloat)constant
{
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:constant];
return constraint;
}
+ (NSLayoutConstraint *)getCenterXConstraintFor:(UIView *)superView with:(UIView *)subView constant:(CGFloat)constant
{
NSLayoutConstraint …Run Code Online (Sandbox Code Playgroud) 当一个图像全屏打开时,我试图实现与照片应用程序中相同的行为; 即,我希望能够在我的不同图像之间滚动,也可以捏缩放其中任何一个.与照片应用程序一样,在我放大特定图像后,我希望能够在我的图库的不同图像之间滚动.
我的情况是这样的:我有一个UICollectionView,定制UICollectionViewFlowLayout其中itemSize被设置为屏幕的大小,和一个自定义UICollectionViewCell有一个UIImageView.这可以很好地滚动浏览不同的照片,问题是滚动到它们.
我尝试的第一种方法是WWDC 2012会话中描述的方法:"高级集合视图和构建自定义布局".使用这种方法获得的效果是细胞正确缩放,但随后它将与其旁边的细胞重叠,从而产生不良影响.
第二种方法类似于WWDC 2010会议中建议的方法:"使用滚动视图设计应用程序".但是,我不完全确定这种方法可以使用UICollectionView而不是UIScrollView +子视图.我将我的视图控制器设置为UIScrollViewDelegate和覆盖viewForZoomingInScrollView:,在那里我返回给定点的可见单元格的UIImageView.如果我这样做,什么都不会发生.我也试过返回单元格,在这种情况下,UICollectionView的整个布局搞砸了.我已经看了Apple放在一起的示例项目(PhotoScroller),它成功地实现了我想要的东西,但在那里它们只是UIImageView一个子视图UIScrollView.
我认为为了用a实现Photos应用程序行为UICollectionView,我需要通过第一种方法并修改集合视图中其他单元格的布局属性而不仅仅是放大的布局属性来实现.
这听起来像是一个非常低级别的解决方案,我想知道是否有人知道更好的方法来解决这个问题.
在我的应用程序中,我有一个层次结构,如主视图 - > UIScrollView - > UISearchBar.搜索栏覆盖整个屏幕宽度.但是当它切换到横向时,滚动视图会根据横向调整自身并覆盖整个屏幕,但其子视图如UISearchBar宽度保持与纵向相同.另外,我正在使用Autolayout,我已经在故事板中正确设置了约束(前导和尾随,宽度(大于等于320)等).
另外我知道在SO中有几个答案,但几乎每个人都会在willAutororate中再次说明设定宽度.但我在UIScrollview中有大约15个子视图,我认为不可能以编程方式设置(增加LOC)加上我认为Autolayout必须有一些解决方案.
我刚刚从iOS 7.1切换到iOS 8.1.我遇到了以下问题UIView animateWithDuration.图片胜过千言万语,我制作了每个iOS下的行为视频:
iOS 7.1:
iOS 8.1:
这是一款iPhone应用程序.
我应该注意到,在发布之前我已经搜索了SO和其他地方.这似乎是一个公认的问题,但我发现的是一些参考"使用基于约束的动画"(我不明白)并关闭自动布局,但没有真正的共识.
我已经尝试了几次刺伤,但没有任何进展.如果有人能指出(或指导我)一个明确的解决方案,我真的很感激.
我应该提一下,该应用程序只能在纵向位置工作,所以我没有考虑在开发过程中自动布局.
所有涉及的视图都是以编程方式创建的,除了滚动条本身.
这是代码.我包括整个方法,这很长,但我真的不明白新iOS中发生了什么变化,所以我是安全的.这个animateWithDuration电话非常深入到这个块中:
-(void) displayDayChart
{
[self.scroller setBackgroundColor:[UIColor clearColor]];
UIImage *image = [UIImage imageNamed:@"GrayPaper.png"];
self.chartView.backgroundColor = [UIColor colorWithPatternImage:image];
[self.view addSubview:self.scroller];
[self.scroller setScrollEnabled:YES];
[self.scroller setContentSize:CGSizeMake(320, 1800)];
[self.scroller setContentOffset:CGPointMake(0.0, 0.0) animated:YES];
dayBarArray = [[NSMutableArray alloc]init];
infoLabelArray = [[NSMutableArray alloc]init];
timeLabelArray = [[NSMutableArray alloc]init];
timeFrameDC = - 86400; // 24 hours for this test, selectable in real life
[self.scroller.subviews makeObjectsPerformSelector: @selector(removeFromSuperview)];
timeframeDCStart = [NSDate dateWithTimeIntervalSinceNow:timeFrameDC];
timeframeDCEnd …Run Code Online (Sandbox Code Playgroud) ios ×4
uiscrollview ×2
animation ×1
autolayout ×1
ios8.1 ×1
iphone ×1
landscape ×1
objective-c ×1
pinchzoom ×1
uiview ×1
zooming ×1