Skip to content

Instantly share code, notes, and snippets.

@pec1985
Last active December 16, 2015 00:38

Revisions

  1. pec1985 revised this gist Apr 9, 2013. 2 changed files with 2 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions TiViewProxy+Extended.h
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    #import "TiViewProxy+Extended.h"

    @interface TiViewProxy(Extended)

    @end
    2 changes: 2 additions & 0 deletions TiViewProxy+Extended.m
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    #import "TiViewProxy+Extended.h"

    @implementation TiViewProxy(Extended)

    -(void)insertViewAfter:(id)args
  2. pec1985 renamed this gist Apr 9, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. pec1985 created this gist Apr 9, 2013.
    5 changes: 5 additions & 0 deletions TiViewProxy+Extended.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    #import "TiViewProxy+Extended.h"

    @interface TiViewProxy(Extended)

    @end
    33 changes: 33 additions & 0 deletions TiViewProxy+Extended.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    @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];
    }
    }
    }
    18 changes: 18 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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();