首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在AQGridView中使用TTImageView

在AQGridView中使用TTImageView
EN

Stack Overflow用户
提问于 2010-10-31 19:50:09
回答 3查看 1.7K关注 0票数 0

我创建了一个自定义的AQGridViewCell。

通过使用UIImageView,一切都能正常工作。图像出现并可单击,但当我将UIImageView更改为TTImageView时,我无法单击该图像。

与下面的示例相同,只需将图像视图更改为UIImageView,并将setter消息更改为图像,一切都会按预期运行。

这是我的ImageGridCell.h

代码语言:javascript
运行
复制
#import "AQGridViewCell.h"
#import <Three20/Three20.h>

@interface ImageGridCell : AQGridViewCell
{
    TTImageView * _imageView;
 NSString *urlPath;
}
@property (nonatomic, retain) NSString *urlPath;

@end

这是我的ImageGridCell.m

代码语言:javascript
运行
复制
#import "ImageGridCell.h"

@implementation ImageGridCell
@synthesize urlPath;

- (id) initWithFrame: (CGRect) frame reuseIdentifier: (NSString *) aReuseIdentifier
{
    self = [super initWithFrame: frame reuseIdentifier: aReuseIdentifier];
    if ( self == nil )
        return ( nil );

    _imageView = [[TTImageView alloc] initWithFrame: CGRectMake(0, 0, 100, 100)];
 [_imageView setContentMode:UIViewContentModeScaleAspectFit];
    [self.contentView addSubview: _imageView];
    return ( self );
}

- (void) dealloc
{
    [_imageView release];
    [super dealloc];
}

- (CALayer *) glowSelectionLayer
{
    return ( _imageView.layer );
}

- (UIImage *) image
{
    return ( _imageView.image );
}
-(void)setUrlPath:(NSString *)urlpath {
 _imageView.urlPath = urlpath;
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-12-08 19:39:08

我遇到了同样的情况,这是我提出的解决方案。我的AQGridViewCell既有TTImageView也有UIImageView。我使用TTImageView加载图像,当它加载时,我将它传递给显示它的UIImageView。

为此,我的AQGridViewCell子类实现了TTImageViewDelegate协议。在我的PostGridViewCell.h中,我有:

代码语言:javascript
运行
复制
@interface PostGridViewCell : AQGridViewCell <TTImageViewDelegate> {
    @private
    TTImageView *ttImageView_;
    UIImageView *imageView_;
}
// @property here …
@end

在我的实现文件中,在initWithFrame:reuseIdentifier:方法中,我初始化了我的ttImageView和imageView,但我只将imageView添加为我的单元格的子视图。并且我将ttImageView委托属性设置为self (这样在加载图像时可以通知我):

代码语言:javascript
运行
复制
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)aReuseIdentifier {
    if ((self = [super initWithFrame:frame reuseIdentifier:aReuseIdentifier])) {
        // init image
        ttImageView_ = [[TTImageView alloc] initWithFrame:CGRectZero];
        ttImageView_.delegate = self;
        imageView_ = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:imageView_];
        // …
    }
    return self;
}

当TTImaveView加载完图像后,它会调用委托(即PostGridViewCell)上的imageView:didLoadImage:方法。在我的实现文件中,我有这个方法:

代码语言:javascript
运行
复制
- (void)imageView:(TTImageView*)imageView didLoadImage:(UIImage*)image {
    self.imageView.image = image;
    [self setNeedsLayout];
}

有帮助吗?

干杯,

托马斯。

票数 1
EN

Stack Overflow用户

发布于 2010-10-31 21:22:34

不太确定你所说的“可点击”是什么意思--比如UIButton?当用户点击其中一个图像时,您希望实现什么行为?

我看不出这里有什么直接的问题,但我可以给你一些可能有帮助的信息。

最重要的是,TTImageView和UIImageView都是从UIView派生出来的,TTImageView不是从UIImageView派生出来的(需要注意的重要一点):

代码语言:javascript
运行
复制
UIImageView : UIView
TTImageView : TTView : UIView

我们不知道UIImageView在幕后发生了什么,所以我看不出有什么不同,但文档似乎清楚地表明,UIImageView对userInteractionEnabled的默认行为是NO -这很奇怪,因为您说它是与UIImageView一起工作,而不是相反。

您是否尝试过在TTImageView上将userInteractionEnabled属性设置为YES

票数 0
EN

Stack Overflow用户

发布于 2011-07-27 03:50:47

这里的问题是TTImageView将userInteractionEnabled设置为YES。因此,触摸事件是由TTImageView举行的,而AQGridView希望在单元格视图中进行触摸。只需将userInteractionEnabled=NO添加到计算单元中的TTImageView中,就可以开始了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4062961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档