Cannot determine when UIImageView frames are equal

大城市里の小女人 提交于 2019-12-12 02:15:35

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/17774370/cannot-determine-when-uiimageview-frames-are-equal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!