Skip to content

Commit 75a04e6

Browse files
committed
Merge pull request #726 from kalo/ui
CCTextField set textfield visibility and enabled
2 parents 0d344be + 2ea8db5 commit 75a04e6

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

cocos2d-ui/CCTextField.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,17 @@ - (void) onExitTransitionDidStart
165165

166166
- (void) update:(CCTime)delta
167167
{
168-
[self positionTextField];
168+
BOOL isVisible = self.visible;
169+
if (isVisible) {
170+
// run through ancestors and see if we are visible
171+
for (CCNode *parent = self.parent; parent && isVisible; parent = parent.parent)
172+
isVisible &= parent.visible;
173+
}
174+
175+
// hide the UITextField if node is invisible
176+
_textField.hidden = !isVisible;
177+
178+
if (isVisible) [self positionTextField];
169179
}
170180

171181
- (void) layout
@@ -189,6 +199,11 @@ - (void) layout
189199
[super layout];
190200
}
191201

202+
- (void) setEnabled:(BOOL)enabled {
203+
_textField.enabled = enabled;
204+
[super setEnabled:enabled];
205+
}
206+
192207
#pragma mark Text Field Delegate Methods
193208

194209
#ifdef __CC_PLATFORM_IOS

0 commit comments

Comments
 (0)