Guest User

Untitled

a guest
Jan 23rd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. -(void)updateImageViewContent {
  2. dispatch_async(
  3. dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
  4. UIImage * img = [UIImage imageNamed:@"background.jpg"];
  5. dispatch_sync(dispatch_get_main_queue(), ^{
  6. [[self imageView] setImage:img];
  7. });
  8. });
  9. }
  10.  
  11. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  12. if (self.tag == 1) {
  13. self.backgroundColor= [UIColor redColor];
  14. }
  15.  
  16. else {
  17. dispatch_async(dispatch_get_main_queue(), ^{
  18. [self setImage:[UIImage imageNamed:@"woodenTile.jpg"]];
  19. });
  20. [UIView animateWithDuration:0.25 animations:
  21. ^(){[self setFrame:CGRectInset(self.frame, 50, 50)];}];
  22. }
  23. }
  24.  
  25. NSURL * url = [ [NSBundle mainBundle]URLForResource:@"bois" withExtension:@"jpg"];
  26. NSURLRequest * request = [NSURLRequest requestWithURL:url];
  27. [self.imageView setImageWithURLRequest:request
  28. placeholderImage:[UIImage imageNamed:@"placeholder.png"]
  29. success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
  30. NSLog(@"success: %@", NSStringFromCGSize([image size]));
  31. } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
  32. NSLog(@"failure: %@", response);
  33. }];
  34.  
  35. // this code works. Used to test that url is valid. But it's blocking the UI as expected.
  36. if (false)
  37. if (url) {
  38. [self.imageView setImage: [UIImage imageWithData:[NSData dataWithContentsOfURL:url]]]; }
  39.  
  40. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
  41. UIImage * img = [UIImage imageNamed:@"background.jpg"];
  42.  
  43. // Make a trivial (1x1) graphics context, and draw the image into it
  44. UIGraphicsBeginImageContext(CGSizeMake(1,1));
  45. CGContextRef context = UIGraphicsGetCurrentContext();
  46. CGContextDrawImage(context, CGRectMake(0, 0, 1, 1), [img CGImage]);
  47. UIGraphicsEndImageContext();
  48.  
  49. // Now the image will have been loaded and decoded and is ready to rock for the main thread
  50. dispatch_sync(dispatch_get_main_queue(), ^{
  51. [[self imageView] setImage: img];
  52. });
  53. });
  54.  
  55. longpress.minimumPressDuration = 0.01;
  56.  
  57. [YourImageView setImageWithURL:[NSURL URLWithString:@"http://image_to_download_from_serrver.jpg"]
  58. placeholderImage:[UIImage imageNamed:@"static_local_image.png"]
  59. success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
  60. //ON success perform
  61. }
  62. failure:NULL];
  63.  
  64. -(void)updateImageViewContent {
  65. dispatch_async(dispatch_get_main_queue(), ^{
  66.  
  67. UIImage * img = [UIImage imageNamed:@"background.jpg"];
  68. [[self imageView] setImage:img];
  69. });
  70. }
  71.  
  72. dispatch_async(dispatch_get_main_queue(), ^{
  73. [self setImage:[UIImage imageNamed:@"woodenTile.jpg"]];
  74. });
  75.  
  76. [self setImage:[UIImage imageNamed:@"woodenTile.jpg"]];
  77.  
  78. FXImageView *imageView = [[FXImageView alloc] initWithFrame:CGRectMake(0, 0, 100.0f, 150.0f)];
  79. imageView.contentMode = UIViewContentModeScaleAspectFit;
  80. imageView.asynchronous = YES;
  81.  
  82. //show placeholder
  83. imageView.processedImage = [UIImage imageNamed:@"placeholder.png"];
  84.  
  85. //set image with URL. FXImageView will then download and process the image
  86. [imageView setImageWithContentsOfURL:url];
  87.  
  88. #import "UIImageView+AFNetworking.h"
  89.  
  90. Use **setImageWithURL** function of AFNetwork....
  91.  
  92. queue = dispatch_queue_create("com.myapp.imageProcessingQueue", DISPATCH_QUEUE_SERIAL);**
  93.  
  94. or
  95.  
  96. queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0);
  97.  
  98. dispatch_async( queue, ^{
  99.  
  100.  
  101.  
  102. // Load UImage from URL
  103. // by using ImageWithContentsOfUrl or
  104.  
  105. UIImage *imagename = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
  106.  
  107. // Then to set the image it must be done on the main thread
  108. dispatch_sync( dispatch_get_main_queue(), ^{
  109. [page_cover setImage: imagename];
  110. imagename = nil;
  111. });
  112.  
  113. });
Add Comment
Please, Sign In to add comment