我有一个带有imageView的scrollView.这scrollView是superView的一个子视图,而imageView是一个子视图scrollView.我还有一个标签(在超级视图级别),每隔毫秒从NSTimer接收其text属性的更新值.
问题是:在滚动期间,标签停止显示更新.滚动结束时,标签上的更新将重新开始.更新重启时,它们是正确的; 这意味着label.text值按预期更新,但在滚动时,更新显示在某处覆盖. 无论滚动与否,我都希望在标签上显示更新.
以下是标签更新的实现方式:
- (void)startElapsedTimeTimer {
[self setStartTime:CFAbsoluteTimeGetCurrent()];
NSTimer *elapsedTimeTimer = [NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(updateElapsedTimeLabel) repeats:YES];
}
- (void)updateElapsedTimeLabel {
CFTimeInterval currentTime = CFAbsoluteTimeGetCurrent();
float theTime = currentTime - startTime;
elapsedTimeLabel.text = [NSString stringWithFormat:@"%1.2f sec.", theTime];
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我正在尝试在imageView中使用单击识别器(也是一个scrollView子项).在Interface Builder中,我只创建并引用了scrollView.滚动工作,但无法识别单击事件(没有记录任何内容).这是代码:
- (void)loadView {
[super loadView];
UIImage *myImage = [UIImage imageNamed:@"img1.jpg"];
imageView = [[UIImageView alloc] initWithImage:myImage];
[myImage release];
// add gesture recognizers to the image view
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[imageView addGestureRecognizer:singleTap];
[singleTap release];
[imageScrollView setContentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)];
[imageScrollView addSubview:imageView]; }
- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {
// single tap handling
NSLog(@"sinlgeTap called"); }
Run Code Online (Sandbox Code Playgroud)
我环顾了几个小时,尝试了很多东西.也许看别人可以帮助更多.谢谢.
我有一个CollectionViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// assign layout (subclassed below)
self.collectionView.collectionViewLayout = [[CustomCollectionLayout alloc] init];
}
// data source is working, here's what matters:
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
ThumbCell *cell = (ThumbCell *)[cv dequeueReusableCellWithReuseIdentifier:@"ThumbCell" forIndexPath:indexPath];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我还有一个UICollectionViewLayout子类:CustomCollectionLayout.m
#pragma mark - Overriden methods
- (CGSize)collectionViewContentSize
{
return CGSizeMake(320, 480);
}
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
return [[super layoutAttributesForElementsInRect:rect] mutableCopy];
}
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
// configure CellAttributes
cellAttributes = [super layoutAttributesForItemAtIndexPath:indexPath];
// random position
int …Run Code Online (Sandbox Code Playgroud)