Wait!!!:
I know that you may think this question have been asked and answered several time before. But I can guarantee you that this question is unique.
Question:
In an iOS App, just imagine two buttons are there, like shown in the image bellow, and they have two actions which behaves like a toggling logic.
And it's logic may be as follows:
- (IBAction)testBtnClicked:(id)sender {
if ([self.testBtn isEnabled]) {
[self.testBtn setEnabled:NO];
[self.setInteractionBtn setUserInteractionEnabled:YES];
} else {
[self.testBtn setEnabled:YES];
[self.setInteractionBtn setUserInteractionEnabled:NO];
}
}
- (IBAction)setInteractionBtnClicked:(id)sender {
if ([self.setInteractionBtn isEnabled]) {
[self.setInteractionBtn setUserInteractionEnabled:NO];
[self.testBtn setEnabled:YES];
} else {
[self.setInteractionBtn setUserInteractionEnabled:YES];
[self.testBtn setEnabled:NO];
}
}
So I don't see a big difference between setEnabled
method and setUserInteractionEnabled
method. They same behave like a single method which blocks the user not letting use it. However if it is same alike, How could we be able to detect isEnabled
true
or false
even when setUserInteractionEnabled
is set to be False
?
Following are the reasons which make this question not a possible duplicate of another Q&A Thread in SO:
- Even though some high ranked code may have marked my question as a possible duplicate, that Q&A didn't give me the correct understanding.
- As @danh said,
At least one reason is that during animation, user interaction is disabled on UIViews. It would be wrong for controls to draw themselves as greyed out while they are animated. So at least during animation, the two properties have distinct meanings.
Gave me the real answer or the reason to see that these two methods are for two reasons. Because anyone could say that setUserInteractionEnabled
doesn't do changes on UI state, but at least only on @danh's answer had first stated that it might be implicitly used during UI Animations.
They are nearly the same.
userInteractionEnabled
is a property ofUIView
that toggles whether the view receives any user touches.enabled
is a property ofUIControl
(which is a subclass ofUIView
and a superclass ofUIButton
) and has the same effect. One difference is that UIKit controls may draw themselves differently depending on theirenabled
state, which isn't the case for the abstractUIView
.Okay, then why?
Since
UIControl
subclasses inherit both, why are there two almost-the-same properties? Why don't controls just drop the idea of "enabled" and draw themselves differently based on theiruserInteractionEnabled
state?At least one reason is that during animation, user interaction is disabled on
UIView
s. It would be wrong for controls to draw themselves as greyed out while they are animated. So at least during animation, the two properties have distinct meanings.