移动时调整 UIButton 上的 imageView 大小

发布于 2024-10-04 08:49:52 字数 600 浏览 4 评论 0原文

在我的应用程序中,我对对象进行了概述。每个对象都是一个UIButton,它有自己的UIImage(button.imageView)。用户可以拖动对象。因此,显示器上部的对象被认为是“在后面”,而下部的对象被认为是“在前面”。后面的对象显示得比前面的对象小。我希望对象在从“前”到“后”移动时动态调整大小,反之亦然。

为此,我使用以下代码(在 UIButton 的子类中):

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    CGFloat h = newHeight;
    CGFloat w = newWidth;

    CGRect target;
    target.size.height = h;
    target.size.width = w;
    self.frame = target;
}

在 iOS 4.2 之前,该代码运行得非常好。现在我们看到非常奇怪的行为:虽然在将对象从“前”移动到“后”(即从大到小)时调整大小有效,但在将对象从“后”移动到“前”(即从大到小)时它不起作用由小到大)。

知道什么可能导致这个问题吗?您将如何实现“移动时调整大小”?

In my application I have an overview of objects. Each object is a UIButton, which has its own UIImage (button.imageView). The user can drag objects around. Thereby, objects in the upper part of the display are considered to be 'in the back' while objects in the lower part are 'in the front'. Objects in the back are displayed smaller than objects in the front. I want the objects to dynamically resize while moving from 'front' to 'back' and vice-versa.

For this purpose, I use the following code (in a subclass of UIButton):

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    CGFloat h = newHeight;
    CGFloat w = newWidth;

    CGRect target;
    target.size.height = h;
    target.size.width = w;
    self.frame = target;
}

This was working very nice up until iOS 4.2. Now we see very strange behaviour: while the resizing works when moving objects from 'front' to 'back' (i.e., from large to small), it DOES NOT work when moving object from 'back' to 'front' (i.e., from small to large).

Any idea what could cause this problem? How would you implement the 'resize while moving'?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文