切换方向会导致 UIButton 重绘
我正在切换到横向,它会重新绘制 UIButton。这是按钮代码。
plusButton = [[[UIButton alloc] initWithFrame:CGRectMake(bounds.size.width - 60.0f, 28.0f, 45.0f,90.0f)] autorelease ];
[plusButton setImage:TTIMAGE(@"bundle://morebutton.png")
forState:UIControlStateNormal];
[plusButton showsTouchWhenHighlighted];
[plusButton addTarget:self action:@selector(plusButtonDidPress:)
forControlEvents:UIControlEventTouchUpInside];
[self addSubview:plusButton];
这是一个 TTMessageitemcell (THREE20)
如有任何建议,我们将不胜感激。谢谢。
I'm switching to landscape and it redraws the UIButton. here is the button code.
plusButton = [[[UIButton alloc] initWithFrame:CGRectMake(bounds.size.width - 60.0f, 28.0f, 45.0f,90.0f)] autorelease ];
[plusButton setImage:TTIMAGE(@"bundle://morebutton.png")
forState:UIControlStateNormal];
[plusButton showsTouchWhenHighlighted];
[plusButton addTarget:self action:@selector(plusButtonDidPress:)
forControlEvents:UIControlEventTouchUpInside];
[self addSubview:plusButton];
This is a TTMessageitemcell (THREE20)
Any suggestions would be appreciated. thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是在drawRect或类似的东西中调用的吗?看起来好像每次调用绘图方法时都会创建按钮的新实例。尝试将加号按钮作为单元格的实例变量,并在 init 方法中对其进行初始化。然后,您可以在绘图方法中设置框架和其他属性,同时仅使用该按钮的一个实例。然后您可以释放dealloc 中的按钮。
tl;dr:看起来好像您在绘图方法中添加按钮的多个实例,例如。 drawRect:或layoutSubviews。
蒂姆
Is this being called in drawRect or something similar? It looks as if it's creating a new instance of the button each time a drawing method is called. Try making plus button an instance variable of your cell and initialise it in the init method. Then you can set frame and other properties in the drawing method while only using one instance of the button. You can then release the button in dealloc.
tl;dr: looks as if you're adding multiple instances of the button in a drawing method eg. drawRect: or layoutSubviews.
Tim