Open cat-aged-noodle-prius opened 9 years ago
here is my swift code . my help some.
var img_arr = ["img01.jpeg","img02.jpeg","img03.jpeg",""]
override func viewDidLoad() {
super.viewDidLoad()
var _scrollview = UIScrollView()
//set up scrollview
_scrollview.frame = CGRectMake(0, 0, view.frame.width, view.frame.width/16*9)
_scrollview.backgroundColor = UIColor.whiteColor()
_scrollview.delegate = self
_scrollview.pagingEnabled = true
_scrollview.showsHorizontalScrollIndicator = false
view.addSubview(_scrollview)
var page_counts = UIPageControl()
//add show page counts
page_counts.frame = CGRectMake(0, view.frame.height-25, view.frame.width, 20)
page_counts.backgroundColor = UIColor.clearColor()
page_counts.pageIndicatorTintColor = UIColor.whiteColor()
page_counts.currentPageIndicatorTintColor = UIColor.orangeColor()
page_counts.alpha = 0.9
// page_counts.currentPage = 0
page_counts.hidesForSinglePage = true
page_counts.defersCurrentPageDisplay = true
view.addSubview(page_counts)
var frame: CGRect = CGRectMake(0, 0, 0, 0)
for var p=0;p<4;p++ {
frame.origin.x = _scrollview.frame.size.width * CGFloat(p)
frame.size = _scrollview.frame.size
//add ytplayer
if p == 3 {
var playerVars:NSDictionary = ["playsinline": "0","rel":"0"]
var videoId = "M7lc1UVf-VE"
var youtubeplayer = YTPlayerView()
// youtubeplayer.delegate = self youtubeplayer.frame = frame youtubeplayer.loadWithVideoId(videoId, playerVars: playerVars as [NSObject : AnyObject]) _scrollview.addSubview(youtubeplayer) youtubeplayer.playVideo() youtubeplayer.playerState()
continue
}
var _imageview = UIImageView()
_imageview.frame = frame
_imageview.contentMode = UIViewContentMode.ScaleAspectFill
_imageview.image = UIImage(named: img_arr[p] )
_scrollview.addSubview(_imageview)
}
frame.origin.x = _scrollview.frame.size.width * CGFloat(4)
frame.size = _scrollview.frame.size
_scrollview.contentSize = CGSizeMake(_scrollview.frame.size.width * CGFloat(4), _scrollview.frame.size.height)
page_counts.numberOfPages = 4
// Do any additional setup after loading the view, typically from a nib.
}
same problem here
I'm creating a UIScrollView that can hold images and videos from different sources. I first created and added a UIView for each image/video to the UIScrollView, then add the image/video view/layer. This works fine for images and videos using AVFoundation; however, does not work for Youtube videos.
Here's my code for adding the YTPlayerView to the UIView within the UIScrollView:
When I try to load the youtube video with loadWithVideoId, the process terminates within YTPlayerView here:
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.bounds];
throwingEXC_BAD_ACCESS
.Interestingly, I've gotten the Youtube videos to show adding the YTPlayerView directly as a subview to
self.view
. Any suggestions?