is it possible to always center my image in the screen if I add to the view and use

Discussion in 'iOS Programming' started by ulquiorra, Sep 7, 2009.

  1. ulquiorra macrumors member

    Joined:
    Jun 17, 2009
    #1
    Does anyone know if it's possible to center my image when using a navigationController.
    With this I mean the following. When I click on a cell everything is fine ( figure 1 )

    figure 1.
    step 1

    http://img441.imageshack.us/img441/5026/picture5t.png

    step 2

    http://img70.imageshack.us/img70/3998/picture6a.png


    I go back and want to click another cell , however this time I like to scroll down and click one of my bottom cells( which are out of my view). Well my imageview is being added only outside the view ( almost at the top of the navigationController , which is correct ) so unless I scroll to the top. Is it possible to have some sort of property with which accesses some sort of current image status and have it centered at all time. So not like this, so that I have to scroll up to see it( figure 2 )

    figure 2


    http://img186.imageshack.us/img186/3012/picture7l.png


    I want to keep using
    Code:
        [self.view addSubview:videoImageView];
    
    Instead of

    Code:
        [self.navigationController.view addSubview:videoImageView];
    
    The latter which pretty much does the trick , unfortunately it does other things as well which are most definately not good;).
    I really want to use the first one.

    Of course a hackish way is making sure my view skips to the toprow of my UITableView when I select one of the rows that are not in "sight".

    Does anyone have a clue or an idea?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    I would suggest not adding as a subview to the current view, but instead presenting a new view as part of a new view controller, either as part of a navigation controller or as a modal view. That way you keep the logic for dealing with the video view separate from the logic for the table view.
     
  3. ulquiorra thread starter macrumors member

    Joined:
    Jun 17, 2009
    #3
    thanks again for your reply.
    Do you mean pushing a new view onto the stack instead of adding it as subView?
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Yes.
     
  5. ulquiorra thread starter macrumors member

    Joined:
    Jun 17, 2009
    #5
    mmm ok ... but wouldn't that mean creating a new nibfile for my imageview?
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Not necessarily. Your view can be defined strictly via code as well, similar to how I believe you are currently doing it.
     
  7. ulquiorra thread starter macrumors member

    Joined:
    Jun 17, 2009
    #7
    I tried your approach

    unfortunately to no avail

    Code:
    [self.navigationController pushViewController:videoImageView animated:YES];
    

    I have to tell you though that my videoImageView is as you can guess an imageview
    Code:
    videoimage = [UIImage imageNamed:pictures];
        videoImageView = [[UIImageView alloc] initWithImage:videoimage];
    	videoImageView.frame = CGRectMake(0, 117 + moveItem, 320, 280);
    
    and the error I'm getting when executing in runtime is this one

    reason: '*** -[UIImageView setParentViewController:]: unrecognized selector

    Forgive my confusion..
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Create a UIViewController and use videoImageView as its view. Then push that. As in:
    Code:
    UIViewController *videoImageViewController = [[UIViewController alloc] init];
    videoImageViewController.view = videoImageView;
    [self.navigationController pushViewController: videoImageViewController animated:YES];
    [videoImageViewController release];
     
  9. ulquiorra thread starter macrumors member

    Joined:
    Jun 17, 2009
    #9
    thnx for your reply and your great answer, perfect..

    fantastic;)!
     

Share This Page