NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self addSubview:webView];
[webView release];
 

 

Draggable items

Here's how to create a simple draggable image.
1. Create a new class that inherits from UIImageView

@interface myDraggableImage : UIImageView { }

2. In the implementation for this new class, add the 2 methods:

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{ // Retrieve the touch point
CGPoint pt = [[touches anyObject] locationInView:self];
startLocation = pt;
[[self superview] bringSubviewToFront:self];
}

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{ // Move relative to the original touch point
CGPoint pt = [[touches anyObject] locationInView:self];
CGRect frame = [self frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[self setFrame:frame];
}

3. Now instantiate the new class as you would any other new image and add it to your view

dragger = [[myDraggableImage alloc] initWithFrame:myDragRect];
[dragger setImage:[UIImage imageNamed:@"myImage.png"]];
[dragger setUserInteractionEnabled:YES];

 

 

CFURLRef baseURL = (CFURLRef) [[NSURL alloc] initFileURLWithPath:sndpath];
AudioServicesCreateSystemSoundID (baseURL, &pmph);
AudioServicesPlaySystemSound(pmph);
[baseURL release];

 

 

 

Threading
1. Create the new thread:

[NSThread detachNewThreadSelector:@selector(myMethod) toTarget:self withObject:nil];

2. Create the method that is called by the new thread:

- (void)myMethod
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
*** code that should be run in the new thread goes here ***
[pool release];
}

What if you need to do something to the main thread from inside your new thread (for example, show a loading symbol)? Use performSelectorOnMainThread.

[self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:false];

 

 

 

[myTimer invalidate]; myTimer = nil; // ensures we never invalidate an already invalid Timer

 

 

 

[plist writeToFile:path atomically:YES];

 

 

Alerts

Show a simple alert with OK button.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:
@"An Alert!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];


Info button
Increase the touchable area on the Info button, so it's easier to press.

CGRect newInfoButtonRect = CGRectMake(infoButton.frame.origin.x-25, infoButton.frame.origin.y-25, infoButton.frame.size.width+50, infoButton.frame.size.height+50);

[infoButton setFrame:newInfoButtonRect];


Detecting Subviews
You can loop through subviews of an existing view. This works especially well if you use the "tag" property on your views.


for (UIImageView *anImage in [self.view subviews])
{
if (anImage.tag == 1)
        { // do something }

相关文章:

  • 2021-09-10
  • 2021-05-16
  • 2022-12-23
  • 2021-05-22
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2022-01-05
相关资源
相似解决方案