我有一个简单的UICollectionView,单元格有一个UITextView.UITextView受限于单元格的边缘,因此它们应保持与单元格大小相同的大小.
我遇到的问题是,由于某种原因,当我通过collectionView指定单元格大小时,这些约束不起作用:layout:sizeForItemAtIndexPath:.
我在故事板中将单元格大小设置为320x50.如果我使用sizeForItemAtIndexPath:返回大小为单元格大小2倍的大小,则尽管我设置了约束,但UITextView仍保持相同的高度.我正在使用Xcode 6 GM.
我的视图控制器代码是:
@implementation TestViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UICollectionViewCell *c = [self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
NSLog(@"%f", c.frame.size.height);
UITextView *tv = (UITextView *)[c viewWithTag:9];
NSLog(@"%f", tv.frame.size.height);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)collectionView.collectionViewLayout; …
Run Code Online (Sandbox Code Playgroud) 我实现了自定义刷新控件(我自己的类,而不是子类),并且由于某些原因,因为移动到iOS 8,设置滚动视图的contentInset(特别是UICollectionView)以启动刷新动画会导致奇怪的跳转/断断续续.这是我的代码:
- (void)containingScrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat scrollPosition = scrollView.contentOffset.y + scrollView.contentInset.top;
if( scrollPosition > 0 || self.isRefreshing )
{
return;
}
CGFloat percentWidth = fabs( scrollPosition ) / self.frame.size.height / 2;
CGRect maskFrame = self.maskLayer.frame;
maskFrame.size.width = self.imageLayer.frame.size.width * percentWidth;
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
self.maskLayer.frame = maskFrame;
[CATransaction commit];
}
- (void)containingScrollViewDidEndDragging:(UIScrollView *)scrollView
{
if( ( self.maskLayer.frame.size.width >= self.imageLayer.frame.size.width ) && !self.isRefreshing )
{
self.isRefreshing = YES;
[self setLoadingScrollViewInsets:scrollView];
[self startAnimation];
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
}
- (void)setLoadingScrollViewInsets:(UIScrollView *)scrollView …
Run Code Online (Sandbox Code Playgroud) 我有一个自定义的UICollectionViewCell与一个不可编辑的,不可选择的UITextView.在cellForItemAtIndexPath:方法中,我设置了UITextView的attributedText属性,它显示了所有属性.但是,当我稍后尝试访问该属性文本时(在点击手势识别器的操作方法中),该值为null.
这是我的代码的样子:
查看控制器:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TNCommentCollectionViewCell *commentCell = [collectionView dequeueReusableCellWithReuseIdentifier:kCommentCellIdentifier
forIndexPath:indexPath];
TNComment *comment = [self.comments objectAtIndex:indexPath.row];
commentCell.textView.attributedText = [self commentStringForComment:comment];
return commentCell;
}
- (NSAttributedString *)commentStringForComment:(DAFeedComment *)comment
{
NSString *usernameString = [NSString stringWithFormat:@"@%@", comment.username];
NSDictionary *usernameAttributes = @{ NSForegroundColorAttributeName : [UIColor usernameColor],
NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Light" size:14.0f] };
NSAttributedString *attributedUsernameString = [[NSAttributedString alloc] initWithString:usernameString attributes:usernameAttributes];
NSMutableAttributedString *labelString = [attributedUsernameString mutableCopy];
NSDictionary *commentAttributes = @{ NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Light" size:14.0f] };
[labelString appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]]; …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用AVCaptureVideoPreviewLayer让相机以横向模式显示,但无论我做什么,相机在横向模式下始终只显示一半的屏幕.
我有它所以我的应用程序只支持Landscape Right,当应用程序启动时,视图方向显然是Landscape Right,但是当我将视频预览图层的框架设置为视图的边界时,就好像它仍然在Portrait中模式.如果我记录视图的宽度和高度,它将打印320x568而不是568x320.
我搜索并查看了与我正在尝试做的相关的每个主题和指南,并且没有找到适用于其中任何一个的解决方案.
这是我的代码(在viewDidLoad中):
// Create video preview layer and add it to the UI
self.videoLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureManager.captureSession];
[[self.view layer] setMasksToBounds:YES];
self.videoLayer.frame = self.view.bounds;
if(self.videoLayer.connection.supportsVideoOrientation)
{
self.videoLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
}
[self.videoLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[self.view.layer addSublayer:self.videoLayer];
[self.captureManager.captureSession startRunning];
Run Code Online (Sandbox Code Playgroud)
上面的代码在我的设备上生成:http: //i.imgur.com/Yz1Bgow.jpg
任何帮助将不胜感激.
所以我提出了各种各样的解决方案.我不知道是否有办法解决这个问题,但这是我能想到的唯一方法,以便在相机出现之前没有延迟.我基本上只是用视图的翻转宽度和高度制作了一个新的CGRect.
这是固定代码:
// Create video preview layer and add it to the UI
self.videoLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureManager.captureSession];
[self.view.layer setMasksToBounds:YES];
CGSize landscapeSize;
landscapeSize.width = self.view.bounds.size.height;
landscapeSize.height = self.view.bounds.size.width;
CGRect landscapeRect;
landscapeRect.size = landscapeSize;
landscapeRect.origin …
Run Code Online (Sandbox Code Playgroud)