-1

I have a UITableView. There are about 5 cells/rows in it.

In each cell there's a button. When a user clicks on the button i need to Display an animated View on top of it. (This view should get animated and displayed from bottom)

  1. According to my code the view doesn't get displayed. How can i solve this?
  2. I need to know how to display the view that animated from the bottom ?
  3. I need the size of the view to take the exact size of the table cell. How can i do this?

my code: cellForRowAtIndexPath

[cell.button addTarget:self action:@selector(buttonclick:) forControlEvents:UIControlEventTouchUpInside];


- (void) buttonclick:(id) sender {

    NewView *newView = [[NewView alloc] init];

    newView.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);

    [self.view addSubview: newView];

in the custom view class

-(id)initWithFrame:(CGRect)frame{    
    self = [super initWithFrame:frame];
    if (self) {

        [[NSBundle mainBundle] loadNibNamed:@"myview" owner:self options:nil];

        self.bounds=self.myview.bounds;

        [self addSubview:self. myview];

    }

    return self;

}
A-Live
  • 8,904
  • 2
  • 39
  • 74
Illep
  • 16,375
  • 46
  • 171
  • 302
  • have you added this : `cell.userInteractionEnabled = NO;`? – Bista Mar 24 '15 at 10:15
  • No i have not. The button gets clicked and the button click event gets fired. – Illep Mar 24 '15 at 10:16
  • Please don't use the quote format simply to highlight the text, it gets confusing. As for the question, your initialiser code is not clear, there's a reference to the property `myview` that is unknown for us, it is related to the first of tour questions and please provide more details to make it clear. As for the custom animation and size calculations, might be a good idea to show what you have done already to make it work. – A-Live Mar 24 '15 at 10:20
  • 1
    Why is this post down voted ? – Illep Mar 24 '15 at 10:21

3 Answers3

0

If NewView is a custom UIView which reimplements drawRect then you need to call setNeedsDisplay

See this answer

Community
  • 1
  • 1
codencandy
  • 1,701
  • 1
  • 10
  • 20
0

Solution of all

- (void) buttonclick:(id) sender {

    UITableViewCell *cell=(UITableViewCell *)[sender superview];


    NewView *newView = [[NewView alloc] initWithFrame:cell.bounds];

    [self.view addSubview: newView];

    //Position the view to the bottom of the view.
    CGRect rect=newView.frame;
    rect.origin.y=self.view.frame.size.height;
    newView.frame=rect;


    //New Position of y to animate from bottom

    rect.origin.y=rect.origin.y-rect.size.height;
    [UIView animateWithDuration:.2 animations:^{
        newView.frame=rect;
    }];

   }

Mistake in your code.

You are not calling initWithFrame as you are loading nib there, so its never called.

Update

You missed one vital point in your custom class code is

self.myview=[[[NSBundle mainBundle] loadNibNamed:@"myview" owner:self options:nil] lastObject];

Hope it helps.

Cheers.

iphonic
  • 12,615
  • 7
  • 60
  • 107
  • still doesn't get displayed. Any clue ? – Illep Mar 24 '15 at 10:25
  • Is there any implementations in *NewView* ? Can you check whether your code getting called in `initWithFrame:` and your myview.bounds have correct values? – iphonic Mar 24 '15 at 10:28
0
    - (void) buttonclick:(id) sender 
    {
        UIButton *button = (UIButton *) sender;
        UIView *senderSuperView = [button superView];// access cell

        NewView *newView = [[NewView alloc] init];

       [newView setFrame: senderSuperView.frame];

       CGAffineTransform newViewActualTransform = newView.transform;

       newView.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);

       [self.view addSubview: newView];

       newView.transform = CGAffineTransformScale(newViewActualTransform, 0.0, 0.0);

       [UIView animateWithDuration:1.0f
                             delay:0
                           options:UIViewAnimationOptionCurveEaseOut
                        animations:^{
        newView.transform = CGAffineTransformScale(newViewActualTransform, 1.0, 1.0);
    }
completion:^(BOOL finished){

    }
    ];
}
Sanjay Mohnani
  • 5,947
  • 30
  • 46