Skip to content

Instantly share code, notes, and snippets.

@pec1985
Last active December 16, 2015 00:38
Show Gist options
  • Save pec1985/5348549 to your computer and use it in GitHub Desktop.
Save pec1985/5348549 to your computer and use it in GitHub Desktop.
Extension to TiViewPrxo to allow "insertViewAfter"
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();
@interface TiViewProxy(Extended)
@end
#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