From 4b80ab096eca7f41995f65d69b40ec7abfd26bcc Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Mon, 30 Dec 2013 15:45:27 +0100 Subject: [PATCH] Adds threading. Uses whole sound --- SpectogramPrototype.xcodeproj/project.pbxproj | 58 ++++++++++----- SpectogramPrototype/AppDelegate.m | 5 +- SpectogramPrototype/AudioFile.m | 10 +-- .../Base.lproj/Main_iPad.storyboard | 19 ++++- SpectogramPrototype/FFTTest.h | 2 +- SpectogramPrototype/FFTTest.m | 2 +- SpectogramPrototype/RuledScrollView.m | 5 +- SpectogramPrototype/Spectographer.h | 2 +- SpectogramPrototype/Spectographer.m | 41 ++++++++--- SpectogramPrototype/ViewController.h | 3 +- SpectogramPrototype/ViewController.m | 72 +++++++++++++++---- 11 files changed, 160 insertions(+), 59 deletions(-) diff --git a/SpectogramPrototype.xcodeproj/project.pbxproj b/SpectogramPrototype.xcodeproj/project.pbxproj index 3a84dcd..c63fa97 100644 --- a/SpectogramPrototype.xcodeproj/project.pbxproj +++ b/SpectogramPrototype.xcodeproj/project.pbxproj @@ -25,10 +25,6 @@ 4261F08818671ECD00AA0EF9 /* ContentView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4261F08718671ECD00AA0EF9 /* ContentView.xib */; }; 426665B51869A7CC005D62AC /* RuledScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 426665B41869A7CC005D62AC /* RuledScrollView.m */; }; 426665B81869CEFE005D62AC /* FFTTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 426665B71869CEFE005D62AC /* FFTTest.m */; }; - 426665BA1869CF73005D62AC /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 426665B91869CF73005D62AC /* Accelerate.framework */; }; - 426665BC1869EF4B005D62AC /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 426665BB1869EF4B005D62AC /* CoreAudio.framework */; }; - 426665C11869F194005D62AC /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 426665C01869F194005D62AC /* AudioToolbox.framework */; }; - 426665C51869F50B005D62AC /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 426665C41869F50B005D62AC /* MediaPlayer.framework */; }; 42ABF54B187035F900B20D82 /* Spectographer.m in Sources */ = {isa = PBXBuildFile; fileRef = 42ABF54A187035F900B20D82 /* Spectographer.m */; }; 42E12A91186F122400866CB3 /* testMusic.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 42E12A90186F122400866CB3 /* testMusic.mp3 */; }; 42E12A94186F1F4C00866CB3 /* AudioFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 42E12A93186F1F4C00866CB3 /* AudioFile.m */; }; @@ -70,10 +66,6 @@ 426665B41869A7CC005D62AC /* RuledScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RuledScrollView.m; sourceTree = ""; }; 426665B61869CEFE005D62AC /* FFTTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FFTTest.h; sourceTree = ""; }; 426665B71869CEFE005D62AC /* FFTTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FFTTest.m; sourceTree = ""; }; - 426665B91869CF73005D62AC /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; }; - 426665BB1869EF4B005D62AC /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; }; - 426665C01869F194005D62AC /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; - 426665C41869F50B005D62AC /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; }; 42ABF549187035F900B20D82 /* Spectographer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Spectographer.h; sourceTree = ""; }; 42ABF54A187035F900B20D82 /* Spectographer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Spectographer.m; sourceTree = ""; }; 42E12A90186F122400866CB3 /* testMusic.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = testMusic.mp3; sourceTree = ""; }; @@ -86,10 +78,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 426665C51869F50B005D62AC /* MediaPlayer.framework in Frameworks */, - 426665C11869F194005D62AC /* AudioToolbox.framework in Frameworks */, - 426665BC1869EF4B005D62AC /* CoreAudio.framework in Frameworks */, - 426665BA1869CF73005D62AC /* Accelerate.framework in Frameworks */, 424F84AB18661F8000687D3B /* CoreGraphics.framework in Frameworks */, 424F84AD18661F8000687D3B /* UIKit.framework in Frameworks */, 424F84A918661F8000687D3B /* Foundation.framework in Frameworks */, @@ -132,10 +120,6 @@ 424F84A718661F8000687D3B /* Frameworks */ = { isa = PBXGroup; children = ( - 426665C41869F50B005D62AC /* MediaPlayer.framework */, - 426665C01869F194005D62AC /* AudioToolbox.framework */, - 426665BB1869EF4B005D62AC /* CoreAudio.framework */, - 426665B91869CF73005D62AC /* Accelerate.framework */, 424F84A818661F8000687D3B /* Foundation.framework */, 424F84AA18661F8000687D3B /* CoreGraphics.framework */, 424F84AC18661F8000687D3B /* UIKit.framework */, @@ -372,30 +356,48 @@ CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES; + CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES; + CLANG_WARN_OBJC_RECEIVER_WEAK = YES; + CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES; + GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; + GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES; + GCC_WARN_PEDANTIC = YES; + GCC_WARN_SHADOW = YES; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_STRICT_SELECTOR_MATCH = YES; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_LABEL = YES; + GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 7.0; ONLY_ACTIVE_ARCH = YES; + RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -412,23 +414,43 @@ CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES; + CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES; + CLANG_WARN_OBJC_RECEIVER_WEAK = YES; + CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES; + GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; + GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES; + GCC_WARN_PEDANTIC = YES; + GCC_WARN_SHADOW = YES; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_STRICT_SELECTOR_MATCH = YES; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_LABEL = YES; + GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 7.0; + RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; diff --git a/SpectogramPrototype/AppDelegate.m b/SpectogramPrototype/AppDelegate.m index 98fa3e9..877ffaf 100644 --- a/SpectogramPrototype/AppDelegate.m +++ b/SpectogramPrototype/AppDelegate.m @@ -9,7 +9,8 @@ #import "AppDelegate.h" @implementation AppDelegate - +@synthesize window; +/* Commented out to silence warnings! - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. @@ -42,5 +43,5 @@ { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } - +*/ @end diff --git a/SpectogramPrototype/AudioFile.m b/SpectogramPrototype/AudioFile.m index e0cd994..eb3f353 100644 --- a/SpectogramPrototype/AudioFile.m +++ b/SpectogramPrototype/AudioFile.m @@ -7,7 +7,7 @@ // #import "AudioFile.h" -#import +@import AudioToolbox.ExtendedAudioFile; @interface AudioFile (){ ExtAudioFileRef audioFile; @@ -76,14 +76,14 @@ short * buffer = bufferList.mBuffers[0].mData; float * leftEnd = left + nSamples; for(unsigned int i = 0; i < nFrames; ++i){ - *left++ = *buffer++ / 32768.0; - *right++ = *buffer++ / 32768.0; + *left++ = *buffer++ / 32768.0f; + *right++ = *buffer++ / 32768.0f; } // assume left and right are of the same size while(left != leftEnd){ - *left++ = 0.0; - *right++ = 0.0; + *left++ = 0; + *right++ = 0; } free(bufferList.mBuffers[0].mData); diff --git a/SpectogramPrototype/Base.lproj/Main_iPad.storyboard b/SpectogramPrototype/Base.lproj/Main_iPad.storyboard index 8bb000f..f4f160c 100644 --- a/SpectogramPrototype/Base.lproj/Main_iPad.storyboard +++ b/SpectogramPrototype/Base.lproj/Main_iPad.storyboard @@ -21,8 +21,8 @@ - + + + + + diff --git a/SpectogramPrototype/FFTTest.h b/SpectogramPrototype/FFTTest.h index 4d2b360..3f67525 100644 --- a/SpectogramPrototype/FFTTest.h +++ b/SpectogramPrototype/FFTTest.h @@ -10,5 +10,5 @@ @interface FFTTest : NSObject - (void) inPlaceFFT:(float*)data forSize:(unsigned int)n; -@property (readonly) unsigned int acceptedSize; +@property (nonatomic, readonly) unsigned int acceptedSize; @end diff --git a/SpectogramPrototype/FFTTest.m b/SpectogramPrototype/FFTTest.m index 488dbfc..f187254 100644 --- a/SpectogramPrototype/FFTTest.m +++ b/SpectogramPrototype/FFTTest.m @@ -7,7 +7,7 @@ // #import "FFTTest.h" -#import +@import Accelerate; @interface FFTTest () { FFTSetup setup; diff --git a/SpectogramPrototype/RuledScrollView.m b/SpectogramPrototype/RuledScrollView.m index 8c793bd..3c2211f 100644 --- a/SpectogramPrototype/RuledScrollView.m +++ b/SpectogramPrototype/RuledScrollView.m @@ -69,7 +69,7 @@ - (void)placeTicks { [topRuler.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; CGFloat spacing = 600.0f; - for (CGFloat x = rulerWidth + 0.5*spacing; x < topRuler.frame.size.width; x += spacing){ + for (CGFloat x = rulerWidth + 0.5f*spacing; x < topRuler.frame.size.width; x += spacing){ UIView * line = [[UIView alloc] initWithFrame:CGRectMake(x, 0, 1, rulerHeight)]; line.backgroundColor = [UIColor blackColor]; [topRuler addSubview:line]; @@ -83,6 +83,7 @@ } - (void)layoutSubviews { + [super layoutSubviews]; { CGRect frame = self.topRuler.frame; frame.origin.y = self.contentOffset.y; @@ -103,7 +104,7 @@ leftRuler.frame = CGRectMake(0, 0, rulerWidth, contentSize.height + rulerHeight); } -- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ +- (UIView *)viewForZoomingInScrollView:(UIScrollView *)__unused scrollView{ return content; } diff --git a/SpectogramPrototype/Spectographer.h b/SpectogramPrototype/Spectographer.h index d62284d..d303531 100644 --- a/SpectogramPrototype/Spectographer.h +++ b/SpectogramPrototype/Spectographer.h @@ -11,6 +11,6 @@ @interface Spectographer : NSObject - (void)openAudioFile:(NSURL*)url; -- (CGImageRef)generate; +- (void)generate:(void (^)(CGImageRef))callback; @end diff --git a/SpectogramPrototype/Spectographer.m b/SpectogramPrototype/Spectographer.m index 72f3b65..9b0b9bf 100644 --- a/SpectogramPrototype/Spectographer.m +++ b/SpectogramPrototype/Spectographer.m @@ -10,10 +10,10 @@ #import "FFTTest.h" #import "AudioFile.h" -UInt8 clamp_to_uint8(float x){ +uint8_t clamp_to_uint8(float x){ if(x >= 1.0) return 255; if(x <= 0.0) return 0; - return 255.0 * x; + return (uint8_t)(255.0f * x); } @interface Spectographer (){ @@ -22,7 +22,8 @@ UInt8 clamp_to_uint8(float x){ float * left; float * right; } - +- (void)threadTask:(void (^)(CGImageRef))callback; +- (CGImageRef)singleStep CF_RETURNS_RETAINED; @end @implementation Spectographer @@ -41,25 +42,43 @@ UInt8 clamp_to_uint8(float x){ assert(audioFile); } -- (CGImageRef)generate{ +- (void)generate:(void (^)(CGImageRef))callback{ + [NSThread detachNewThreadSelector:@selector(threadTask:) toTarget:self withObject:callback]; +} + +- (void)threadTask:(void (^)(CGImageRef))callback{ + CGImageRef cgImage = nil; + while((cgImage = [self singleStep])){ + callback(cgImage); + CGImageRelease(cgImage); + } +} + +- (CGImageRef)singleStep{ unsigned int size = FFTHandler.acceptedSize; - unsigned int width = size/4; + unsigned int width = 128; unsigned int height = size/8; - char * rgba = calloc(width*height*4, sizeof(char)); + uint8_t * rgba = calloc(width*height*4, sizeof(uint8_t)); - for(unsigned int x = 0; x < width; ++x){ - [audioFile fillLeft:left andRight:right withNumberOfSamples:size]; + unsigned int x = 0; + for(; x < width; ++x){ + if(![audioFile fillLeft:left andRight:right withNumberOfSamples:size]) + break; [FFTHandler inPlaceFFT:left forSize:size]; [FFTHandler inPlaceFFT:right forSize:size]; for(unsigned int y = 0; y < height; ++y){ unsigned int yy = height - y - 1; - rgba[4*width*yy + 4*x + 0] = clamp_to_uint8(100.0 * left[y]); - rgba[4*width*yy + 4*x + 1] = clamp_to_uint8(100.0 * right[y]); - rgba[4*width*yy + 4*x + 2] = clamp_to_uint8(10.0 * (left[y] + right[y])); + rgba[4*width*yy + 4*x + 0] = clamp_to_uint8(100.0f * left[y]); + rgba[4*width*yy + 4*x + 1] = clamp_to_uint8(100.0f * right[y]); + rgba[4*width*yy + 4*x + 2] = clamp_to_uint8(10.0f * (left[y] + right[y])); rgba[4*width*yy + 4*x + 3] = 0; } } + if(!x){ + free(rgba); + return nil; + } CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); assert(colorSpace); diff --git a/SpectogramPrototype/ViewController.h b/SpectogramPrototype/ViewController.h index b2cad6d..70d4992 100644 --- a/SpectogramPrototype/ViewController.h +++ b/SpectogramPrototype/ViewController.h @@ -15,6 +15,7 @@ @property (nonatomic) IBOutlet RuledScrollView * scrollView; @property (nonatomic) IBOutlet UIView * contentView; -- (IBAction) mediaButtonPressed:(UIButton*)sender; +- (IBAction)mediaButtonPressed:(UIButton*)sender; +- (IBAction)resetView:(id)sender; @end diff --git a/SpectogramPrototype/ViewController.m b/SpectogramPrototype/ViewController.m index dc5f6e2..09eff1f 100644 --- a/SpectogramPrototype/ViewController.m +++ b/SpectogramPrototype/ViewController.m @@ -6,8 +6,7 @@ // Copyright (c) 2013 Joshua Moerman. All rights reserved. // -#import -#import +@import MediaPlayer.MPMediaPickerController; #import "ViewController.h" #import "RuledScrollView.h" @@ -40,8 +39,11 @@ device get_device(){ @interface ViewController () { Spectographer * spectographer; UIPopoverController * pop; + NSMutableArray * slices; } -- (void) openAudioFile:(NSURL*)filePath; +- (void)openAudioFile:(NSURL*)filePath; +- (void)addSlice:(UIImageView*)view; +- (void)removeAllSlices; @property (nonatomic, strong) UILabel* header; @end @@ -58,6 +60,10 @@ device get_device(){ contentView.autoresizingMask = UIViewAutoresizingNone; scrollView.contentSize = contentView.bounds.size; } + + if(!slices){ + slices = [[NSMutableArray alloc] init]; + } } - (void)didReceiveMemoryWarning{ @@ -65,26 +71,58 @@ device get_device(){ } - (void)openAudioFile:(NSURL *)filePath{ + [self removeAllSlices]; if(!spectographer) spectographer = [[Spectographer alloc] init]; [spectographer openAudioFile:filePath]; - CGImageRef image = [spectographer generate]; - - UIImage * newUIImage = [UIImage imageWithCGImage:image]; - assert(newUIImage); + [spectographer generate:^void(CGImageRef image){ + CGImageRetain(image); + dispatch_async(dispatch_get_main_queue(), ^{ + UIImage * newUIImage = [UIImage imageWithCGImage:image]; + assert(newUIImage); + CGImageRelease(image); + + UIImageView * view = [[UIImageView alloc] initWithImage:newUIImage]; + [self addSlice:view]; + }); + }]; - CGImageRelease(image); +// [contentView removeFromSuperview]; +// contentView = view; +// scrollView.zoomScale = 1.0; +// +// [scrollView.content addSubview:contentView]; +// contentView.autoresizingMask = UIViewAutoresizingNone; +// scrollView.contentSize = contentView.bounds.size; +} + +- (void)addSlice:(UIImageView *)view{ + if(slices.count){ + UIImageView * lastSlice = slices.lastObject; + float x = CGRectGetMaxX(lastSlice.frame); + view.frame = CGRectOffset(view.frame, x, 0); + } // else leave the origin at 0 - UIImageView * view = [[UIImageView alloc] initWithImage:newUIImage]; + [contentView addSubview:view]; + [slices addObject:view]; - [contentView removeFromSuperview]; - contentView = view; + UIImageView * lastSlice = slices.lastObject; + scrollView.contentSize = CGSizeMake(CGRectGetMaxX(lastSlice.frame), CGRectGetMaxY(lastSlice.frame)); +} + +- (void)removeAllSlices{ + for(UIView * view in slices){ + [view removeFromSuperview]; + } + [slices removeAllObjects]; + scrollView.contentSize = CGSizeZero; +} + +- (void)resetView:(id)__unused sender{ scrollView.zoomScale = 1.0; - - [scrollView.content addSubview:contentView]; - contentView.autoresizingMask = UIViewAutoresizingNone; - scrollView.contentSize = contentView.bounds.size; + UIImageView * lastSlice = slices.lastObject; + scrollView.contentSize = CGSizeMake(CGRectGetMaxX(lastSlice.frame), CGRectGetMaxY(lastSlice.frame)); } - (void)mediaButtonPressed:(UIButton*)sender{ @@ -128,11 +166,15 @@ device get_device(){ } [pop dismissPopoverAnimated:YES]; pop = nil; + + [mediaPicker dismissViewControllerAnimated:YES completion:nil]; } - (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker { [pop dismissPopoverAnimated:YES]; pop = nil; + + [mediaPicker dismissViewControllerAnimated:YES completion:nil]; } @end