Last active
December 16, 2015 00:38
Extension to TiViewPrxo to allow "insertViewAfter"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var view1 = Ti.UI.createView({ | |
backgroundColor: 'red', | |
height: 100 | |
}); | |
var view2 = Ti.UI.createView({ | |
backgroundColor: 'blur', | |
height: 100 | |
}); | |
var win = Ti.UI.createWindow({}); | |
win.add(view1); | |
win.insertViewAfter({ | |
view: view2, | |
after: view1 | |
}); | |
win.open(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface TiViewProxy(Extended) | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "TiViewProxy+Extended.h" | |
@implementation TiViewProxy(Extended) | |
-(void)insertViewAfter:(id)args | |
{ | |
ENSURE_SINGLE_ARG(args, NSDictionary) | |
TiViewProxy *_view = [args objectForKey:@"view"]; | |
TiViewProxy *_after = [args objectForKey:@"after"]; | |
NSMutableArray *arr = [NSMutableArray array]; | |
for(TiViewProxy *child in children) | |
{ | |
[arr addObject:child]; | |
} | |
NSInteger afterIndex = 0; | |
for (NSInteger i = 0; i < [children count]; ++i) { | |
if ([_after isEqual: [children objectAtIndex:i]]) { | |
afterIndex = i; | |
} | |
[self remove:[children objectAtIndex:i]]; | |
} | |
for(NSInteger i = 0, len = [arr count]; i < len; i++) | |
{ | |
[self add:[arr objectAtIndex:i]]; | |
if(i == afterIndex) | |
{ | |
[self add:_view]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment