I'm completely new to Xcode, and I need a little help ...
I Has created the Coco project, and then has opened the main.exib file in "Interface Builder".
From the interface builder, I added an NSImageView object, and in the image set of a GIF file inside my resource folder, in the project.
I have to know how I can apply, so that the location of every millisecond can be changed in the NSIMEview.
Can anyone illuminate me?
- G
Once you have an imageView in your .h file To connect to the outlet, implement the following:
In your .h file:
@interface YourViewController: UIViewController {NSTimer * mainTimer; BOOL timer enabled; }
In your .m file:
- (zero) viewDidload {Main Timer = [NSTM Scheduled Timer with Time Interval: 1 Goal: Self Selector : @Selector (UpdateTime) userInfo: Zero repeats: Yes]; TimerIsEnabled = TRUE; [Super viewedload]; } - (zero) update time {if (timeris enabled) {float dx = arc4random ()% 768 + 1; Float dy = arc4random ()% 1004 + 1; CGPoint newPoint = CGPEX (DX, DI); UIView * touchView = imageView; Name midpoint x = CGRectGetMidX (touchview.bound); // if too far right ... if (newpoint x gt; self.view.bounds.size.width - midpoint x) newPoint.x = self.view.bounds.size.width - midpointX; And if (newpoint x. Midpoint x) // is very far left ... newpoint.x = midpoint x; Boat midPointY = CGRectGetMidY (touchView.bounds); // If too far below ... if (newpoint.y> self.view.bounds.size.height - midpoint) newpoint Y = self.view.bounds.size.height - midpoint; And if (newpoint.y & lt; midpointointy) // very far ... newpoint.y = midpoint; TouchView.center = newPoint; }} - (zero) viewDidUnload {[invalid timer invalid]; [See self set image: zero]; [Super viewload]; // release any maintained subview of main view eg Self.myOutlet = Zero; }
You can also create a button to start and stop the timer:
- Go to (IBAction): (ID) sender {timerIsEnabled =! Timer is enabled; }
Comments
Post a Comment