0

I'm using UIScrollView to create recording timeline just like Voice Memo app. This is horizontal scrollview's frame at the beginning. I use CAShapeLayer to draw bars.

 scrlViewBars.frame = CGRectMake(0, scrlViewBars.frame.origin.y, SCREEN_WIDTH, 100);
    ....
 [shapeLayer setPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, barWidth, barHeight) cornerRadius:2] CGPath]];
 [scrlViewBars.layer addSublayer:shapeLayer];

Recording starts and draws wave bars from beginning i.e wave bars are created from zero X position of UIScrollView. When bars will reach to the half of the screen, I start moving UIScrollView back by giving contentSize and contentOffset. So bars then will remain in centre after that just like Voice Memo app.

Everything works great except proper UIScrollView timeline. If the recording is small, contentSize will not be larger than screen width. So is it possible to UIScrollView to go below 0 contentOffSet? Because after recording is stopped, user can scroll timeline and starting content of recording should go till centre of the screen because there is a scrub bar at the centre which will not move and shows current recording time.

Bhavin Ramani
  • 3,221
  • 5
  • 30
  • 41
Hiren Prajapati
  • 717
  • 3
  • 10
  • 25

1 Answers1

0

You can set the contentInset property to have some inset from left, that should do the trick.

self.scrollView.contentInset = UIEdgeInsetsMake(0, self.scrollView.frame.size.width/2, 0, 0);

Hope this helps.

nishith Singh
  • 2,968
  • 1
  • 15
  • 25
  • thanks for answering. I already tried it. The problem is that at beginning bars will be created from zeroth position. scroll will not move until bars reach at half screen.Then I'm moving scroll view. so If record is too small. I face problems here. – Hiren Prajapati Oct 20 '16 at 11:38
  • Then you can try using min contentSize as the scrollView's width. With that done even if your waves are small your contentInset will do the magic. – nishith Singh Oct 20 '16 at 11:45
  • thanks for the idea. I will work on it and let you know – Hiren Prajapati Oct 20 '16 at 12:56
  • I use AVAudioRecorder to record audio. What should be recommended now for audio cropping anywhere from timeline and record over from there? So I want cropping and merging. Please reply as soon as possible – Hiren Prajapati Oct 21 '16 at 06:18
  • You can use AVAssetExportSession please refer this answer http://stackoverflow.com/questions/9698787/ios-audio-trimming – nishith Singh Oct 21 '16 at 09:06
  • done it already using AVAssetExportSession and AVMutableComposition. Thanks :) – Hiren Prajapati Oct 21 '16 at 11:52