Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Moving the controls...

luckysmilesluckysmiles Posts: 140Registered Users
edited November 2010 in iPhone SDK Development
Hi everyone,

Pls anyone help me...how to move controls(like button,label.. ) from one place to another using touch events in iphone..

Thanks in advance...
Post edited by luckysmiles on
«1

Replies

  • Oliver DrobnikOliver Drobnik Vienna, AustriaPosts: 538New Users, Registered Users @ @ @
    edited November 2010
    Hi everyone,

    Pls anyone help me...how to move controls(like button,label.. ) from one place to another using touch events in iphone..

    Thanks in advance...

    That is too broad a question. you can always change the frame property of a control based on a drag gesture. Either use a gesture recognizer or add a target for the drag event.
    Buy my book "Barcodes with iOS 7": http://bitly.com/barcodes_iOS

    Get 50% until March 9th with promo code "mldrobnik"
  • luckysmilesluckysmiles Posts: 140Registered Users
    edited November 2010
    Thank u for ur response Oliver....

    I'm to this technology...
    if u don't mind..can u explain how to do that..Please....
  • luckysmilesluckysmiles Posts: 140Registered Users
    edited November 2010
    Thank u for ur response Oliver....

    I'm new to this technology...
    if u don't mind..can u explain how to do that..Please....
  • baja_yubaja_yu Posts: 6,188Moderators, Registered Users Admin
    edited November 2010
    Be sure to check the documentation. Apple provided great docs and even sample code. To learn about gesture recognizers look here Loading…
    There's even sample code: Loading…
  • iphone_bharatiphone_bharat Posts: 108Registered Users
    edited November 2010
    Thanks baja_yu for ur replies everywhere on this forum ... but with full respect and no offense ... just giving the links of sample docs always doesn't help ... if u can't give the answer in detail .. better avoid giving the answer ... that's my view ...
    I would also want to take the attention of moderators here ... that this could unnecessarily irritate the user who ask the question .. and would snatch away the attention of someone who could answer properly in more detail ...because always apple docs dont help .. and thats why the beginners come here for help ... and baja_yu I am pointing this at u after seing many of ur replies just giving the links to apple docs ... and pls (no offence ...)
  • iphone_bharatiphone_bharat Posts: 108Registered Users
    edited November 2010
    And for ur question luckysmiles .. suppose if u want that for label ... u can subclass the label and add gesture recognizer to it or on its touches began and touches moved method can set the frame of the label as below : -
    -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
    		
    	touchlocation = [[touches anyObject]locationInView:self];
    
    	
    }
    -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
    	CGPoint newtouchlocation = [[touches anyObject]locationInView:self];
    	float deltaX = newtouchlocation.x-touchlocation.x;
    	float deltaY = newtouchlocation.y-touchlocation.y;
    	CGRect tframe = [self frame];
    	tframe.origin.x+=deltaX;
    	tframe.origin.y+=deltaY;
    	[self setFrame:tframe];
    }
    
    
  • baja_yubaja_yu Posts: 6,188Moderators, Registered Users Admin
    edited November 2010
    It's my belief that the purpose of this forum is to share knowledge, help people learn, not to have others do all the work.

    In this particular example the OP is not familiar with gesture recognizers (and is new to the platform over all). Do you really think it's helpful to give him code that he can copy/paste and use without understanding how or why it works?
    Also, I'm not a fan of giving answers if I don't see a person putting in some effort. As the saying goes, give a man a fish and you'll feed him for a day, teach him how to fish and you'll feed him for a lifetime.

    The documentation is there for a reason, and Apple provides really good one (from all that I've seen over the past 15 years).
    I'm new to the platform too (not to programming in general), but I've spent a month and read over 3000 pages of documentation before even starting with a Hello World.
  • luckysmilesluckysmiles Posts: 140Registered Users
    edited November 2010
    Thank you iphone_bharat...

    Definitely I will try it in few mins..and i will post my feedback on this..

    i was searched regarding to this topic in google..but i didn't found any solution...
    Thank you so much..
  • iphone_bharatiphone_bharat Posts: 108Registered Users
    edited November 2010
    I agree , baja , that sometimes giving links is only useful but its not the case always as ur doing everywhere in this forum ,,, an apple document can be found easily by google .. so how u r helping the OP ... just by reducing his effort of searching on google ... I totally disagree on that ... just spreading the links on the forum is not the idea of this forum ...
    and anyways .. sometimes codes are the things from which we learn a lot .. and thats why apple has also provided sample codes ... so why cant we give some code snippets to OP if he want that ..
    and for the saying of fish... u r not teaching him to how to fish ...u r giving a "Book in German language how to Fish" to a person who only knows English and doesn't know German language ..
  • luckysmilesluckysmiles Posts: 140Registered Users
    edited November 2010
    Hi iphone_bharat...

    I have one doubt..
    In ur code..self is what(label or uiview or uiviewcontroller)...
    b'coz i got errors on that....

    Actually i was taken viewcontroller and i place label on that viewcontroller's view..,now i want to move that label from one place to another...
    So,i select label's property as multitouched and user interaction enabled..and i wrote the touch events methods what u r specified..
    but,when i was running the app and touches the label..then the app crashes...

    Pls help me..
  • iphone_bharatiphone_bharat Posts: 108Registered Users
    edited November 2010
    Hi iphone_bharat...

    I have one doubt..
    In ur code..self is what(label or uiview or uiviewcontroller)...
    b'coz i got errors on that....

    Actually i was taken viewcontroller and i place label on that viewcontroller's view..,now i want to move that label from one place to another...
    So,i select label's property as multitouched and user interaction enabled..and i wrote the touch events methods what u r specified..
    but,when i was running the app and touches the label..then the app crashes...

    Pls help me..
    U have to learn about subclassing ... I mean u have to subclass ur label and then define ur touches methods on that ... and u must have understood now that "self" is "uilabel subclass" ..
  • baja_yubaja_yu Posts: 6,188Moderators, Registered Users Admin
    edited November 2010
    Unfortunately it's obvious that some people never tried finding a solution for themselves. A lot of the questions asked can be trivially solved by doing a Google search, searching the documentation, and even searching this forum as the question might (and usually has) been asked and answered before. Pointing them to a resource like the docs might get them to start using it on their own.
    Of course, as you said, that's not always the case.

    In this example, where the person is new and has no idea how to approach a specific problem, I think that pointing them to the right spot in the documentation is a perfect answer. If the OP reads those few pages on gesture recognizers he will be more than able to solve the problem on his own, and he learned a lot in the process. Giving him code to paste in won't help him in the long run.

    But, you have your opinion, I have mine. I don't think we should derail this thread off-topic anymore. If you want we can move the discussion elsewhere (different thread, different forum section).
  • baja_yubaja_yu Posts: 6,188Moderators, Registered Users Admin
    edited November 2010
    U have to learn about subclassing ... I mean u have to subclass ur label and then define ur touches methods on that ... and u must have understood now that "self" is "uilabel subclass" ..

    That is exactly what I was talking about, giving someone code which they do not understand.

    Reading may not be fun but it's a great way to learn.
  • iphone_bharatiphone_bharat Posts: 108Registered Users
    edited November 2010
    yes.. everything can be found on google .. but sometimes our keywords are not right and we fail to search an existing solution and thats where this forum come as helping hand ...
    And what I clearly said that "may be u r right in this case " but u r doing the same thing in every case and that was disturbing ...
    but here I agree with u that we should not de-rail the thread anymore ...
    However I would like to start a discussion and know exactly from member as well as the moderators ... that what is this forum for " for getting the links of apple docs " or " for getting some explanations in the form of code snippets or otherwise"
  • luckysmilesluckysmiles Posts: 140Registered Users
    edited November 2010
    Thank u so much iPhone_bharat...

    It's working...
    i'm very thankful to u..
    b'coz i was fresher and new to this technology...this moving label is one of the tasks in my requirement...today,u gave solution to it...

    Thanks...
  • iphone_bharatiphone_bharat Posts: 108Registered Users
    edited November 2010
    @luckysmiles -- I hope u learnt something from it and just dint copy paste the code ... as I used to do .. and thats like i have grown up in programming by learning from the codes ..
    I hope i havenot just fed u the fish .. rather taught u how to hold the hook ..
  • baja_yubaja_yu Posts: 6,188Moderators, Registered Users Admin
    edited November 2010
    but u r doing the same thing in every case and that was disturbing ...

    I disagree with that strongly. If I feel the user has no general idea on how to approach a problem I might give a general response and suggestions. But for specific problems I give specific suggestions, code samples etc.
    However I would like to start a discussion and know exactly from member as well as the moderators ... that what is this forum for " for getting the links of apple docs " or " for getting some explanations in the form of code snippets or otherwise"

    If you do start a discussion thread on the subject please do invite me to it via PM.
  • iphone_bharatiphone_bharat Posts: 108Registered Users
    edited November 2010
    If I feel the user has no general idea on how to approach a problem I might give a general response and suggestions.
    I have always seen u doing that (just giving links)
    But for specific problems I give specific suggestions, code samples etc.
    Never seen that
    If you do start a discussion thread on the subject please do invite me to it via PM.
    Copy to you ..
  • luckysmilesluckysmiles Posts: 140Registered Users
    edited November 2010
    Please don't fight both of u guys..

    Both of ur discussions r correct...

    As i was a fresher..i didn't know exactly how to find the solution..
    So,i approach this forum....

    i'm sure i didn't copy and paste blindly..
    i will try to understand the code..and if i have any doubts then i will approach u..

    Thank u..
  • iphone_bharatiphone_bharat Posts: 108Registered Users
    edited November 2010
    dn't worry this is not a fight ... this is just a discussion ... and basically an offtrack discussion which appears sometimes in between all the codes and expalinations and programming ... which rather binds this forum and not divide this forum .. enjoy and learn ... iphonedevsdkforum.com
  • Oliver DrobnikOliver Drobnik Vienna, AustriaPosts: 538New Users, Registered Users @ @ @
    edited November 2010
    i'm sure i didn't copy and paste blindly..
    i will try to understand the code..and if i have any doubts then i will approach u..

    Thank u..

    I elaborated on 2 or the 3 mentioned techniques in this article: Draggable Buttons and Labels @ Cocoanetics
    Buy my book "Barcodes with iOS 7": http://bitly.com/barcodes_iOS

    Get 50% until March 9th with promo code "mldrobnik"
  • luckysmilesluckysmiles Posts: 140Registered Users
    edited November 2010
    Hi iPhone_bharat...

    Again i have one more doubt...
    As i already told that my app is view based app and i was placed label on that viewcontroller's view..and i make that label as ib outlet and perform touch events on that...

    here my problem is i want the label to move only when i was touching it..its working..but,also it was moving when i was touching the view also...

    my view property is set to user interaction enabled....
    if i disable it then moving operation doesn't works...
    Help me pls.....
  • Oliver DrobnikOliver Drobnik Vienna, AustriaPosts: 538New Users, Registered Users @ @ @
    edited November 2010
    here my problem is i want the label to move only when i was touching it..its working..but,also it was moving when i was touching the view also...

    Have a look at the tutorial I made especially for you!
    Buy my book "Barcodes with iOS 7": http://bitly.com/barcodes_iOS

    Get 50% until March 9th with promo code "mldrobnik"
  • iphone_bharatiphone_bharat Posts: 108Registered Users
    edited November 2010
    I think u have not subclassed ur uilabel and detecting ur touches on ur viewcontroler's view... u have to subclasss ur uilabel and detect touches only on that.. I hope u know about subclassing ... if not have look at "Subclassing objects" ...
    if u r not clear enpugh .. msg me ur skype id and we can discuss ur problem there ...
  • luckysmilesluckysmiles Posts: 140Registered Users
    edited November 2010
    Hi Oliver...
    Thank u so much for a nice tutorial...

    I will try it in few mins..
    Once again Thank u so much..
«1
Sign In or Register to comment.