无法确定何时uiimageView帧相等[英] Cannot determine when UIImageView frames are equal

本文是小编为大家收集整理的关于无法确定何时uiimageView帧相等的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有两层.底层由隐藏的UIImageView s组成,上层由可见的UIImageView s组成.当底层的所有帧UIImageView s等于上层UIImageView s的帧时,您必须在NSLog中看到.

问题在于,NSTimer调用的布尔方法总是立即返回true,因此我看到NSLog.当所有相应的帧彼此相等时,我只想看到NSLog.

这是我的代码:

- (void)checkTheFrames {
    BOOL allEquals = [self isEqualFrames];
    if (allEquals) {
        NSLog(@"ALL THE FRAMES ARE EQUAL");
        [AllPosCorrectTimer invalidate];
    }
}

-(BOOL)isEqualFrames {
    for(int i = 0; i < arrayImg.count; i++ ){
        UIImageView *ImageView1 = arrayImg[i];
        UIImageView *ImageView2 = HiddenFieldView[i];
        if (!CGRectEqualToRect(ImageView1.frame, ImageView2.frame)) {
            return NO;
        }
    }
    return YES;
}

有没有办法解决此问题?

推荐答案

我认为错是在比较XS和YS ...也许您应该进一步访问frame.size并进行比较.或者可以轻松比较宽度和高度(frame1.size.width == frame2.size.width)

让我知道这是否没有解决问题!

本文地址:https://www.itbaoku.cn/post/2091192.html

问题描述

I have two layers. The bottom layer consists of hidden UIImageViews, the upper layer consists of visible UIImageViews. When all the frames of the bottom layer UIImageViews are equal to the frames of the upper layer UIImageViews, you have to see that in a NSLog.

The problem is that the boolean method which is called by a NSTimer always returns true immediately, so I see the NSLog. I only want to see the NSLog when all corresponding frames are equal to each other.

This is my code:

- (void)checkTheFrames {
    BOOL allEquals = [self isEqualFrames];
    if (allEquals) {
        NSLog(@"ALL THE FRAMES ARE EQUAL");
        [AllPosCorrectTimer invalidate];
    }
}

-(BOOL)isEqualFrames {
    for(int i = 0; i < arrayImg.count; i++ ){
        UIImageView *ImageView1 = arrayImg[i];
        UIImageView *ImageView2 = HiddenFieldView[i];
        if (!CGRectEqualToRect(ImageView1.frame, ImageView2.frame)) {
            return NO;
        }
    }
    return YES;
}

Is there a way to solve this issue?

推荐答案

I think whats wrong is that you're comparing the Xs and Ys too... maybe you should go further to frame.size and compare them. Or maybe compare the widths and heights easily (frame1.size.width == frame2.size.width)

Let me know if this didn't solve the problem!