ios - When to use UITouch vs UIScroll -


i achieve design see in dating apps. can vertically scroll images of profile , horizontally scroll view next or previous person in list.

currently have views laid out such.

previous-uiview  -      current uiview -    next uiview      uiscrollview.           uiscrollview.       uiscrollview         images.                 images.             images     uiview.                 uiview.             uiview         profile info.           profile info.       profile info     uipagecontrol.          uipagecontrol       uipagecontrol. 

only 1 of views occupies main view next , previous off screen. ideally when user moves view left programmatically remove previous view, make current previous, next current , add new view next. visa versa moving right.

what best way scroll views horizontally?

should wrap them in uiscrollview? , interfere uiscrollview sub views?

or should program touch controls move views?

or there better way?

i'm still newbie @ ios development appreciated.

so i've tried experimenting test app , i'm pleased can have uiscrollviews inside uiscrollviews.

i able running perfectly. here code below.

    override func viewdidload() {     super.viewdidload()      self.superview.delegate = self      // additional setup after loading view, typically nib.     var subimages1 = ["img_0004.jpg","img_0005.jpg","img_0008.jpg"]     var subimages2 = ["img_0009.jpg","img_0010.jpg","img_0011.jpg"]     var subimages3 = ["img_0013.jpg","img_0017.jpg","img_0018.jpg"]     self.images.append(subimages1)     self.images.append(subimages2)     self.images.append(subimages3)     self.superview.frame = self.view.frame     self.superview.contentsize = cgsizemake(self.view.frame.width*3, self.view.frame.height)     self.superview.contentoffset = cgpoint(x:self.view.frame.width,y:0)     self.superview.pagingenabled = true     self.view.addsubview(self.superview)       //layout uiveiws master scrollview     in 0...2{         var offset = self.view.frame.width * cgfloat(i)         var pview = uiview()         pview.frame = cgrectmake(offset, 0, self.view.frame.width, self.view.frame.height)         pview.backgroundcolor = colours[i]         self.superview.addsubview(pview)         self.profileviews.append(pview)      }      // add sub scroll views , images views.     (index, view) in enumerate(self.profileviews){         var scrollview = uiscrollview()         scrollview.delegate = self         scrollview.frame = cgrectmake(10, 10, self.view.frame.width-20, self.view.frame.height-20)         scrollview.pagingenabled = true         scrollview.contentsize = cgsizemake(scrollview.frame.width, scrollview.frame.height * cgfloat(images[index].count))         (index2, image) in enumerate(images[index]){             var subimage = uiimageview()             subimage.frame = cgrectmake(0, scrollview.frame.height * cgfloat(index2), scrollview.frame.width, scrollview.frame.height)             subimage.contentmode = uiviewcontentmode.scaleaspectfit             subimage.image = uiimage(named: image as! string)             scrollview.addsubview(subimage)         }         view.addsubview(scrollview)         self.scrollviews.append(scrollview)       } }  //use did end decelerating executes code once scoll has finished moving. func scrollviewdidenddecelerating(scrollview: uiscrollview) {     if(scrollview == self.superview){         var contentoffset = scrollview.contentoffset         var pagewidth = self.superview.frame.width         var fractionalpage:double = double(self.superview.contentoffset.x / pagewidth)         var page = lround(fractionalpage)           // in example take last uiview stack , move first.         // same in real app update contents of view after         if(page == 0){             var tempview = self.profileviews[2]             self.profileviews[2].removefromsuperview()             self.profileviews.removeatindex(2)             view in self.profileviews{                  view.frame  = cgrectmake(view.frame.minx + self.view.frame.width, 0, view.frame.width, view.frame.height)                 println(view.frame)             }             tempview.frame = cgrectmake(0, 0, tempview.frame.width, tempview.frame.height)             self.profileviews.insert(tempview, atindex: 0)             self.superview.addsubview(tempview)             var newoffset = contentoffset.x + pagewidth              self.superview.contentoffset = cgpoint(x: newoffset, y: 0)          }         // take first view , move last.         if(page == 2){             var tempview = self.profileviews[0]             self.profileviews[0].removefromsuperview()             self.profileviews.removeatindex(0)             view in self.profileviews{                  view.frame  = cgrectmake(view.frame.minx - self.view.frame.width, 0, view.frame.width, view.frame.height)                 println(view.frame)             }             tempview.frame = cgrectmake(tempview.frame.width*2, 0, tempview.frame.width, tempview.frame.height)             self.profileviews.append(tempview)             self.superview.addsubview(tempview)             var newoffset = contentoffset.x - pagewidth              self.superview.contentoffset = cgpoint(x: newoffset, y: 0)          }      } } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -