Add UIView in Main View As UItabBarController in swift - swift

I am adding Tabbarcontroller in Main View, but i didn't set its background colour... I have already try tabBar.barTintColor but it's not working..
So i am trying to Add View as TabbarController (Which work like UITabbar) but i am not succeeded on it... Can any one please help me out.Here is the code
var tabBar = UITabBarController()
var frameOfView : CGRect = UIScreen.mainScreen().bounds
tabBar.view.frame = CGRectMake(frameOfView.origin.x, frameOfView.size.height, frameOfView.size.width, frameOfView.size.height-100)
var viewTabBar = UIView(frame: CGRectMake(frameOfView.origin.x, 430, frameOfView.size.width, 100))
var BtnHomeTab = UIButton(frame: CGRectMake(0, 0, 30, 30))
var imageHomeTab = UIImage(named: "home_selected.png")
viewTabBar.addSubview(BtnHomeTab)

have to hide UITabbarcontroller ..:)
and then Add this code to Your appDelegate.
//MARK: CREATE BOTTOMBAR BUTTON
func craeteBottonBarButton()
{
var viewBottom : UIView = UIView(frame: CGRectMake(0,window!.frame.size.height - 50.0,window!.frame.size.width,60.0))
viewBottom.tag = TagWindow.Tag_Bottom.rawValue
window!.addSubview(viewBottom)
window!.bringSubviewToFront(viewBottom)
viewBottom.backgroundColor = GlobalConstants.GlobalConstants.ButtonConstant.BUTTONBACKGROUNDCOLOR
viewBottom.tag = TagWindow.Tag_Bottom.rawValue
var x : CGFloat = 0.0
for var i = 0 ; i < 5 ; i++
{
var btn = createTabBarButton(viewBottom,
framebtn: CGRectMake(x,0, 65.0, 50.0),
tag: (i + 1),
imgName: arrayImage.objectAtIndex(i) as NSString , btnName: arrayLblName.objectAtIndex(i) as NSString) as UIButton
viewBottom.addSubview(btn)
x += 64.5
}
}
Give all navigation controller to the button
func createTabBar() -> UITabBarController
{
var storyBoard = UIStoryboard(name: "Main", bundle: nil)
tabBar.delegate = self
var tabBarFont = UITabBar()
let HomeTab = storyBoard.instantiateViewControllerWithIdentifier("HomeVC") as HomeVC
let navigation_home = UINavigationController(rootViewController: HomeTab)
navigation_home.navigationBarHidden = true
let SearchTab = storyBoard.instantiateViewControllerWithIdentifier("SearchVC") as SearchVC
let navigation_search = UINavigationController(rootViewController: SearchTab)
navigation_search.navigationBarHidden = true
let SettingTab = storyBoard.instantiateViewControllerWithIdentifier("SettingVC") as SettingVC
let navigation_Setting = UINavigationController(rootViewController: SettingTab)
navigation_Setting.navigationBarHidden = true
let MySeatTab = storyBoard.instantiateViewControllerWithIdentifier("MySeatVC") as MySeatVC
let navigation_MySeat = UINavigationController(rootViewController: MySeatTab)
navigation_MySeat.navigationBarHidden = true

Related

CAEmitterLayer doesn't work in MacOS with Swift

I just simply create a storyboard program, and change the main ViewController code to the code below which works well in others' example. but it appears nothing on the view? seeking help.
What I did:
create an project with storyboard, and I got 'AppDelegate.swift' and 'ViewController.swift'
paste 'Ball_green.png' to my project and see it under the file tree of my project.
paste the code below in 'ViewController.swift'
import Cocoa
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
self.view.wantsLayer = true
self.addLayer()
}
func addLayer(){
let rootLayer = self.view.layer
let snowEmitter = CAEmitterLayer()
snowEmitter.drawsAsynchronously = true
snowEmitter.name = "snowEmitter"
snowEmitter.zPosition = 10.0
snowEmitter.emitterPosition = CGPoint(x: 0, y: 0)
snowEmitter.renderMode = CAEmitterLayerRenderMode.backToFront
snowEmitter.emitterShape = CAEmitterLayerEmitterShape.circle
snowEmitter.emitterZPosition = -43.00
snowEmitter.emitterSize = CGSize(width: 160, height: 160)
snowEmitter.velocity = 20.57
snowEmitter.emitterMode = CAEmitterLayerEmitterMode.points
snowEmitter.birthRate = 10
let snowFlakesCell2 = CAEmitterCell()
snowFlakesCell2.emissionRange = .pi
snowFlakesCell2.lifetime = 10.0
snowFlakesCell2.birthRate = 4.0
snowFlakesCell2.velocity = 2.0
snowFlakesCell2.velocityRange = 100.0
snowFlakesCell2.yAcceleration = 300.0
snowFlakesCell2.contents = NSImage(named: "Ball_green.png")!.cgImage
snowFlakesCell2.magnificationFilter = convertFromCALayerContentsFilter(CALayerContentsFilter.nearest)
snowFlakesCell2.scale = 0.72
snowFlakesCell2.scaleRange = 0.14
snowFlakesCell2.spin = 0.38
snowFlakesCell2.spinRange = 0
snowEmitter.emitterCells = [snowFlakesCell2]
rootLayer!.addSublayer(snowEmitter)
}
}
fileprivate func convertFromCALayerContentsFilter(_ input: CALayerContentsFilter) -> String {
return input.rawValue
}
extension NSImage {
var cgImage: CGImage {
get {
let imageData = self.tiffRepresentation
let source = CGImageSourceCreateWithData(imageData as! CFData, nil)
let maskRef = CGImageSourceCreateImageAtIndex(source!, 0, nil)
return maskRef!
}
}
}
I've solved the problem after adding the code.

swift custom context menu previewprovider can not click any view inside(using tapgesture)

im working with reaction like message, here is what i did (using customProvider from contextMenu)
below is the code when i added emoji action to customProvider controller
private func addReactionList(_ items : [Reaction]) -> UIView{
let reactionView = UIView()
var arrangedSubviews: [UIView] = []
for reaction in items {
let imgView = UIImageView(image: AppUtils.reactionToImage(reaction: reaction))
imgView.isUserInteractionEnabled = true
imgView.frame = CGRect(x: 0, y: 0, width: iconHeight, height: iconHeight)
imgView.layer.cornerRadius = (imgView.frame.height) / 2
imgView.layer.masksToBounds = true
imgView.layer.borderColor = UIColor.clear.cgColor
imgView.layer.borderWidth = 0
imgView.contentMode = .scaleAspectFit
imgView.restorationIdentifier = reaction.Type
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))
tapGesture.delegate = self
tapGesture.numberOfTapsRequired = 1
tapGesture.delaysTouchesBegan = true
tapGesture.cancelsTouchesInView = false
imgView.isUserInteractionEnabled = true
imgView.addGestureRecognizer(tapGesture)
arrangedSubviews.append(imgView)
}
let stackView = UIStackView(arrangedSubviews: arrangedSubviews)
stackView.distribution = .fillEqually
stackView.spacing = padding
stackView.layoutMargins = UIEdgeInsets(top: padding, left: padding, bottom: padding, right: padding)
stackView.isLayoutMarginsRelativeArrangement = true
let width = (CGFloat(items.count) * iconHeight) + (CGFloat(items.count+1) * padding)
reactionView.frame = CGRect(x: 0, y: 0, width: width, height: iconHeight + 2 * padding)
reactionView.layer.cornerRadius = 12
reactionView.addSubview(stackView)
stackView.frame = reactionView.frame
stackView.isUserInteractionEnabled = false
reactionView.isUserInteractionEnabled = false
return reactionView
}
then i added this to custom provider vc:
let actionsReacts = addReactionList(likeReactions)
let emojiReacts = addReactionList(emojiReactions)
if let snap = customView.snapshotView(afterScreenUpdates: true) as UIView?{
view.addSubview(snap)
view.addSubview(actionsReacts)
view.addSubview(emojiReacts)
let maxWidth = snap.frame.size.width >= actionsReacts.frame.size.width ? snap.frame.size.width : actionsReacts.frame.size.width
var currentSnapFrame = snap.frame
currentSnapFrame = CGRect(Int((maxWidth - snap.frame.size.width)) / 2, 0 , Int(snap.frame.size.width), Int(snap.frame.size.height))
snap.frame = currentSnapFrame
var currentActionsReactFrame = actionsReacts.frame
currentActionsReactFrame = CGRect(0, Int(snap.frame.size.height), Int(actionsReacts.frame.size.width), Int(actionsReacts.frame.size.height))
actionsReacts.frame = currentActionsReactFrame
var currentEmojiReactFrame = actionsReacts.frame
currentEmojiReactFrame = CGRect(0, Int(snap.frame.size.height) + Int(emojiReacts.frame.size.height), Int(emojiReacts.frame.size.width), Int(emojiReacts.frame.size.height))
emojiReacts.frame = currentEmojiReactFrame
preferredContentSize = CGSize(width: maxWidth, height: snap.frame.size.height + actionsReacts.frame.size.height + emojiReacts.frame.size.height)
}
But the gesture can not fire, i tried to change img to button, but still not get click
#objc func handleTapGesture(_ sender : UITapGestureRecognizer){
let tappedImage = sender.view as! UIImageView
let reactionType = tappedImage.restorationIdentifier ?? ""
onSelectedReaction?(reactionType)
}
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
return true
}
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
i do not know why i can not click any where, even i tried to add gesture click to viewcontroller view. Can anyone explain it? Thanks in advance
i changed to present new VC with hero animation, so bored, but it is my best choice for now
I tried to reconstruct your demo app from what you have provided, but it is still not clear to me what your code is or how it behaves.
One thing I note that you are creating n gesture-recognizers and hooking each to an imageview.
Try instead using 1 gesture recognizer. Hook it to your parent view, and on tap-event, get the subview which is being hit.
Some code:
let tap = UITapGestureRecognizer(target: self, action: #selector(self.onViewTap))
parentView.addGestureRecognizer(tap)
#objc func onViewTap(_ sender: UITapGestureRecognizer) {
let point = sender.location(in: containerView)
if let hitSubview = parentView.hitTest(point, with: nil) {
// check which subview (imageView) is being hit by checking its tag or similar
}

Everything in the paged scroll view is to the right

I have looked at similar problems on stack overflow and google, however my problem is not solved. I designed an app which uses a page scroll view in the Main.storyboard, which scrolls horizontally between other storyboards[pages]. I used the video Snapchat-Like Menu by Jared Davidson to help me.
Before, It was in the center, as I would expect it to. I think it changed when I updated to Xcode 8(But am not certain). However, everything is to the right. I think it changed when I updated to Xcode 8(But am not certain) I have tried updating the frames but it has been unsuccessful. Attached are some images to help show you the problem as well as my ViewController code.
What could I do?
Thank you in advance.
//
// ViewController.swift
//
//
// Created by Lucas Farleigh on 13/08/2016.
//
import UIKit
class ViewController: UIViewController {
#IBOutlet var MyScrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
//Declaring the child views
let VM : TitlePageViewController = TitlePageViewController(nibName: "TitlePageViewController", bundle: nil)
let V1 : View1 = View1(nibName: "View1", bundle: nil)
let V2 : View2 = View2(nibName: "View2", bundle: nil)
let V3 : View3 = View3(nibName: "View3", bundle: nil)
let V4 : View4 = View4(nibName: "View4", bundle: nil)
let V5 : View5 = View5(nibName: "View5", bundle: nil)
let V6 : View6 = View6(nibName: "View6", bundle: nil)
let V7 : View7 = View7(nibName: "View7", bundle: nil)
let V8 : View8 = View8(nibName: "View8", bundle: nil)
let V9 : View9 = View9(nibName: "View9", bundle: nil)
let V10 : View10 = View10(nibName: "View10", bundle: nil)
let V11 : View11 = View11(nibName: "View11", bundle: nil)
let V12 : View12 = View12(nibName: "View12", bundle: nil)
let V13 : View13 = View13(nibName: "View13", bundle: nil)
let V14 : View14 = View14(nibName: "View14", bundle: nil)
let V15 : View15 = View15(nibName: "View15", bundle: nil)
let V16 : View16 = View16(nibName: "View16", bundle: nil)
let V17 : View17 = View17(nibName: "View17", bundle: nil)
let V18 : View18 = View18(nibName: "View18", bundle: nil)
let V19 : View19 = View19(nibName: "View19", bundle: nil)
let V20 : View20 = View20(nibName: "View20", bundle: nil)
let V21 : View21 = View21(nibName: "View21", bundle: nil)
let V22 : View22 = View22(nibName: "View22", bundle: nil)
let V23 : View23 = View23(nibName: "View23", bundle: nil)
let V24 : View24 = View24(nibName: "View24", bundle: nil)
let V25 : View25 = View25(nibName: "View25", bundle: nil)
let V26 : View26 = View26(nibName: "View26", bundle: nil)
let V27 : View27 = View27(nibName: "View27", bundle: nil)
let V28 : View28 = View28(nibName: "View28", bundle: nil)
let V29 : View29 = View29(nibName: "View29", bundle: nil)
let V30 : View30 = View30(nibName: "View30", bundle: nil)
let V31 : View31 = View31(nibName: "View31", bundle: nil)
let V32 : View32 = View32(nibName: "View32", bundle: nil)
let V33 : View33 = View33(nibName: "View33", bundle: nil)
let V34 : View34 = View34(nibName: "View34", bundle: nil)
let V35 : View35 = View35(nibName: "View35", bundle: nil)
let V36 : View36 = View36(nibName: "View36", bundle: nil)
let V37 : View37 = View37(nibName: "View37", bundle: nil)
let V38 : View38 = View38(nibName: "View38", bundle: nil)
let V39 : View39 = View39(nibName: "View39", bundle: nil)
let V40 : View40 = View40(nibName: "View40", bundle: nil)
let V41 : View39 = View39(nibName: "View41", bundle: nil)
let V42 : View40 = View40(nibName: "View42", bundle: nil)
//Decraling that the child views are child views
self.addChildViewController(VM)
self.addChildViewController(V1)
self.addChildViewController(V2)
self.addChildViewController(V3)
self.addChildViewController(V4)
self.addChildViewController(V5)
self.addChildViewController(V6)
self.addChildViewController(V7)
self.addChildViewController(V8)
self.addChildViewController(V9)
self.addChildViewController(V10)
self.addChildViewController(V11)
self.addChildViewController(V12)
self.addChildViewController(V13)
self.addChildViewController(V14)
self.addChildViewController(V15)
self.addChildViewController(V16)
self.addChildViewController(V17)
self.addChildViewController(V18)
self.addChildViewController(V19)
self.addChildViewController(V20)
self.addChildViewController(V21)
self.addChildViewController(V22)
self.addChildViewController(V23)
self.addChildViewController(V24)
self.addChildViewController(V25)
self.addChildViewController(V26)
self.addChildViewController(V27)
self.addChildViewController(V28)
self.addChildViewController(V29)
self.addChildViewController(V30)
self.addChildViewController(V31)
self.addChildViewController(V32)
self.addChildViewController(V33)
self.addChildViewController(V34)
self.addChildViewController(V35)
self.addChildViewController(V36)
self.addChildViewController(V37)
self.addChildViewController(V38)
self.addChildViewController(V39)
self.addChildViewController(V40)
self.addChildViewController(V41)
self.addChildViewController(V42)
//Adding the view into the scrollview (MyScrollView)
/**/ self.MyScrollView.addSubview(VM.view)
self.MyScrollView.addSubview(V1.view)
self.MyScrollView.addSubview(V2.view)
self.MyScrollView.addSubview(V3.view)
self.MyScrollView.addSubview(V4.view)
self.MyScrollView.addSubview(V5.view)
self.MyScrollView.addSubview(V6.view)
self.MyScrollView.addSubview(V7.view)
self.MyScrollView.addSubview(V8.view)
self.MyScrollView.addSubview(V9.view)
self.MyScrollView.addSubview(V10.view)
self.MyScrollView.addSubview(V11.view)
self.MyScrollView.addSubview(V12.view)
self.MyScrollView.addSubview(V13.view)
self.MyScrollView.addSubview(V14.view)
self.MyScrollView.addSubview(V15.view)
self.MyScrollView.addSubview(V16.view)
self.MyScrollView.addSubview(V17.view)
self.MyScrollView.addSubview(V18.view)
self.MyScrollView.addSubview(V19.view)
self.MyScrollView.addSubview(V20.view)
self.MyScrollView.addSubview(V21.view)
self.MyScrollView.addSubview(V22.view)
self.MyScrollView.addSubview(V23.view)
self.MyScrollView.addSubview(V24.view)
self.MyScrollView.addSubview(V25.view)
self.MyScrollView.addSubview(V26.view)
self.MyScrollView.addSubview(V27.view)
self.MyScrollView.addSubview(V28.view)
self.MyScrollView.addSubview(V29.view)
self.MyScrollView.addSubview(V30.view)
self.MyScrollView.addSubview(V31.view)
self.MyScrollView.addSubview(V32.view)
self.MyScrollView.addSubview(V33.view)
self.MyScrollView.addSubview(V34.view)
self.MyScrollView.addSubview(V35.view)
self.MyScrollView.addSubview(V36.view)
self.MyScrollView.addSubview(V37.view)
self.MyScrollView.addSubview(V38.view)
self.MyScrollView.addSubview(V39.view)
self.MyScrollView.addSubview(V40.view)
self.MyScrollView.addSubview(V41.view)
self.MyScrollView.addSubview(V42.view)
//Confirming that it did move to the view controller
/**/ VM.didMove(toParentViewController: self)
V1.didMove(toParentViewController: self)
V2.didMove(toParentViewController: self)
V3.didMove(toParentViewController: self)
V4.didMove(toParentViewController: self)
V5.didMove(toParentViewController: self)
V6.didMove(toParentViewController: self)
V7.didMove(toParentViewController: self)
V8.didMove(toParentViewController: self)
V9.didMove(toParentViewController: self)
V10.didMove(toParentViewController: self)
V11.didMove(toParentViewController: self)
V12.didMove(toParentViewController: self)
V13.didMove(toParentViewController: self)
V14.didMove(toParentViewController: self)
V15.didMove(toParentViewController: self)
V16.didMove(toParentViewController: self)
V17.didMove(toParentViewController: self)
V18.didMove(toParentViewController: self)
V19.didMove(toParentViewController: self)
V20.didMove(toParentViewController: self)
V21.didMove(toParentViewController: self)
V22.didMove(toParentViewController: self)
V23.didMove(toParentViewController: self)
V24.didMove(toParentViewController: self)
V25.didMove(toParentViewController: self)
V26.didMove(toParentViewController: self)
V27.didMove(toParentViewController: self)
V28.didMove(toParentViewController: self)
V29.didMove(toParentViewController: self)
V30.didMove(toParentViewController: self)
V31.didMove(toParentViewController: self)
V32.didMove(toParentViewController: self)
V33.didMove(toParentViewController: self)
V34.didMove(toParentViewController: self)
V35.didMove(toParentViewController: self)
V36.didMove(toParentViewController: self)
V37.didMove(toParentViewController: self)
V38.didMove(toParentViewController: self)
V39.didMove(toParentViewController: self)
V40.didMove(toParentViewController: self)
V41.didMove(toParentViewController: self)
V42.didMove(toParentViewController: self)
//SIZES AND POSITIONS
//Declaring how big the scroll view is
self.MyScrollView.contentSize = CGSize(width: self.view.frame.width * 43, height: self.view.frame.height)
//Setting the frame of the Views
var V1Frame : CGRect = V1.view.frame
var V2Frame : CGRect = V2.view.frame
var V3Frame : CGRect = V3.view.frame
var V4Frame : CGRect = V4.view.frame
var V5Frame : CGRect = V5.view.frame
var V6Frame : CGRect = V6.view.frame
var V7Frame : CGRect = V7.view.frame
var V8Frame : CGRect = V8.view.frame
var V9Frame : CGRect = V9.view.frame
var V10Frame : CGRect = V10.view.frame
var V11Frame : CGRect = V11.view.frame
var V12Frame : CGRect = V12.view.frame
var V13Frame : CGRect = V13.view.frame
var V14Frame : CGRect = V14.view.frame
var V15Frame : CGRect = V15.view.frame
var V16Frame : CGRect = V16.view.frame
var V17Frame : CGRect = V17.view.frame
var V18Frame : CGRect = V18.view.frame
var V19Frame : CGRect = V19.view.frame
var V20Frame : CGRect = V20.view.frame
var V21Frame : CGRect = V21.view.frame
var V22Frame : CGRect = V22.view.frame
var V23Frame : CGRect = V23.view.frame
var V24Frame : CGRect = V24.view.frame
var V25Frame : CGRect = V25.view.frame
var V26Frame : CGRect = V26.view.frame
var V27Frame : CGRect = V27.view.frame
var V28Frame : CGRect = V28.view.frame
var V29Frame : CGRect = V29.view.frame
var V30Frame : CGRect = V30.view.frame
var V31Frame : CGRect = V31.view.frame
var V32Frame : CGRect = V32.view.frame
var V33Frame : CGRect = V33.view.frame
var V34Frame : CGRect = V34.view.frame
var V35Frame : CGRect = V35.view.frame
var V36Frame : CGRect = V36.view.frame
var V37Frame : CGRect = V37.view.frame
var V38Frame : CGRect = V38.view.frame
var V39Frame : CGRect = V39.view.frame
var V40Frame : CGRect = V40.view.frame
var V41Frame : CGRect = V41.view.frame
var V42Frame : CGRect = V42.view.frame
//Making it off the screen to the right
V1Frame.origin.x = self.view.frame.width
V2Frame.origin.x = 2 * self.view.frame.width
V3Frame.origin.x = 3 * self.view.frame.width
V4Frame.origin.x = 4 * self.view.frame.width
V5Frame.origin.x = 5 * self.view.frame.width
V6Frame.origin.x = 6 * self.view.frame.width
V7Frame.origin.x = 7 * self.view.frame.width
V8Frame.origin.x = 8 * self.view.frame.width
V9Frame.origin.x = 9 * self.view.frame.width
V10Frame.origin.x = 10 * self.view.frame.width
V11Frame.origin.x = 11 * self.view.frame.width
V12Frame.origin.x = 12 * self.view.frame.width
V13Frame.origin.x = 13 * self.view.frame.width
V14Frame.origin.x = 14 * self.view.frame.width
V15Frame.origin.x = 15 * self.view.frame.width
V16Frame.origin.x = 16 * self.view.frame.width
V17Frame.origin.x = 17 * self.view.frame.width
V18Frame.origin.x = 18 * self.view.frame.width
V19Frame.origin.x = 19 * self.view.frame.width
V20Frame.origin.x = 20 * self.view.frame.width
V21Frame.origin.x = 21 * self.view.frame.width
V22Frame.origin.x = 22 * self.view.frame.width
V23Frame.origin.x = 23 * self.view.frame.width
V24Frame.origin.x = 24 * self.view.frame.width
V25Frame.origin.x = 25 * self.view.frame.width
V26Frame.origin.x = 26 * self.view.frame.width
V27Frame.origin.x = 27 * self.view.frame.width
V28Frame.origin.x = 28 * self.view.frame.width
V29Frame.origin.x = 29 * self.view.frame.width
V30Frame.origin.x = 30 * self.view.frame.width
V31Frame.origin.x = 31 * self.view.frame.width
V32Frame.origin.x = 32 * self.view.frame.width
V33Frame.origin.x = 33 * self.view.frame.width
V34Frame.origin.x = 34 * self.view.frame.width
V35Frame.origin.x = 35 * self.view.frame.width
V36Frame.origin.x = 36 * self.view.frame.width
V37Frame.origin.x = 37 * self.view.frame.width
V38Frame.origin.x = 38 * self.view.frame.width
V39Frame.origin.x = 39 * self.view.frame.width
V40Frame.origin.x = 40 * self.view.frame.width
V41Frame.origin.x = 41 * self.view.frame.width
V42Frame.origin.x = 42 * self.view.frame.width
//Adding it on to the view
V1.view.frame = V1Frame
V2.view.frame = V2Frame
V3.view.frame = V3Frame
V4.view.frame = V4Frame
V5.view.frame = V5Frame
V6.view.frame = V6Frame
V7.view.frame = V7Frame
V8.view.frame = V8Frame
V9.view.frame = V9Frame
V10.view.frame = V10Frame
V11.view.frame = V11Frame
V12.view.frame = V12Frame
V13.view.frame = V13Frame
V14.view.frame = V14Frame
V15.view.frame = V15Frame
V16.view.frame = V16Frame
V17.view.frame = V17Frame
V18.view.frame = V18Frame
V19.view.frame = V19Frame
V20.view.frame = V20Frame
V21.view.frame = V21Frame
V22.view.frame = V22Frame
V23.view.frame = V23Frame
V24.view.frame = V24Frame
V25.view.frame = V25Frame
V26.view.frame = V26Frame
V27.view.frame = V27Frame
V28.view.frame = V28Frame
V29.view.frame = V29Frame
V30.view.frame = V30Frame
V31.view.frame = V31Frame
V32.view.frame = V32Frame
V33.view.frame = V33Frame
V34.view.frame = V34Frame
V35.view.frame = V35Frame
V36.view.frame = V36Frame
V37.view.frame = V37Frame
V38.view.frame = V38Frame
V39.view.frame = V39Frame
V40.view.frame = V40Frame
V41.view.frame = V41Frame
V42.view.frame = V42Frame
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
This doesn't directly answer your question, but what you're doing is totally wrong and you need to abandon it. 42 view controllers with 42 screen-sized views, all of them in the scroll view at the same time, is just bad practice.
Switch to using UIPageViewController. It is a paged horizontal scroller, it does what you're trying to do, and it does it efficiently — only one view controller and one view exists at any one moment.

Cannot change the size of a popover

I've been trying to create my own code, as well as copy and paste examples, but my popover seems to fill the entire screen. Generally my code looks like below, but like I said, I've tried at least two other examples (some with CGSizeMake(), sourceRect, sourceView), and the results are always the same.
Class TableView: UITableViewController, UIPopoverPresentationControllerDelegate {
let popover = UIViewController()
func someButton() {
popover.modalPresentationStyle = .Popover
popover.preferredContentSize = CGSize(1, 1)
let menu = popover.popoverPresentationController
menu!.delegate = self
menu!.barButtonItem = someOtherCorrectButton
self.presentViewController(popover, animated: true, completion: nil)
}
}
What's the problem?
Try below code
popover.modalPresentationStyle = .Popover
var popupHeight:CGFloat = 542
let popupWidth = 400 as CGFloat
popover.preferredContentSize = CGSizeMake(400,popupHeight)
let window = UIApplication.sharedApplication().delegate!.window!!
let screenSize: CGRect = window.bounds
var XCordinate = (screenSize.width - popupWidth) / 2
var YCordinate = (screenSize.height / 2) + 20
let menu = popover.popoverPresentationController
menu!.delegate = self
menu!.sourceView = window
menu!.sourceRect = CGRect( x: XCordinate, y: YCordinate, width: 1, height: 1)
self.presentViewController(popover, animated: true, completion: nil)
May be it works for you.

Delete ImageView From SubScrollView In Swift

I am having main ScrollView with pages Enable..Under that I have Subscrollviews and ImageView to display images..I want to Delete Selected image from main scrollview..I don't have any idea to how to get that selected imageView from scrollview and remove it...Here is my code...
func createScroll()
{
var arrayImage = NSUserDefaults.standardUserDefaults().objectForKey("ImageArray") as NSMutableArray
var index = NSUserDefaults.standardUserDefaults().objectForKey("Index") as Int
var scroll = UIScrollView(frame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height))
var page = UIPageControl(frame: CGRectMake(0, 0, scroll.frame.size.width, scroll.frame.size.height))
page.numberOfPages = arrayImage.count
page.currentPage = 0
page.autoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth
scroll.contentSize = CGSizeMake(scroll.frame.size.width * CGFloat(arrayImage.count - 1) , 0)
scroll.delegate = self
scroll.pagingEnabled = true
scroll.maximumZoomScale = 6
scroll.minimumZoomScale = 0.5
scroll.tag = Tags.Tag_MainScroll.rawValue
scroll.addSubview(page)
view.addSubview(scroll)
scroll.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
scroll.contentOffset = CGPointMake(scroll.frame.size.width * CGFloat(index - 1) , 0)
}
//MARK: Display Selected Image
func displayImage()
{
var mainScroll : UIScrollView = view.viewWithTag(Tags.Tag_MainScroll.rawValue) as UIScrollView
var arrayImage = NSUserDefaults.standardUserDefaults().objectForKey("ImageArray") as NSMutableArray
var xPosition : CGFloat = 0
for i in 1...22
{
var subScroll = UIScrollView(frame: CGRectMake(xPosition, 0, view.frame.size.width, view.frame.size.height))
subScroll.delegate = self
subScroll.maximumZoomScale = 6
subScroll.minimumZoomScale = 0.5
subScroll.tag = Tags.Tag_SubScroll.rawValue + i
mainScroll.addSubview(subScroll)
var imgToDisplay : UIImage = UIImage(named: "\(arrayImage[i])")! as UIImage
var imgView : UIImageView = UIImageView(frame: CGRectMake((subScroll.frame.size.width - 100 ) / 2,(subScroll.frame.size.height - 100) / 2, 100, 100))
subScroll.contentSize = CGSizeMake(imgView.frame.size.width, imgView.frame.size.height)
imgView.image = imgToDisplay
imgView.tag = Tags.Tag_imgView.rawValue
subScroll.addSubview(imgView)
xPosition += subScroll.frame.size.width
}
}
Here Is my Delete Function...
func Delete()
{
var imgView : UIImageView? = view.viewWithTag(Tags.Tag_imgView.rawValue) as? UIImageView
var scroll : UIScrollView = view.viewWithTag(Tags.Tag_MainScroll.rawValue) as UIScrollView
for img in scroll.subviews
{
imgView = img as? UIImageView
imgView?.removeFromSuperview()
}
}`
have u tryed this one..
let subViews = self.scrollView.subviews
for subview in subViews{
subview.removeFromSuperview()
}
HERE is the reference
as per my code this Delete Function is working for me
func Delete()
{
var imgView : UIImageView? = view.viewWithTag(Tags.Tag_imgView.rawValue) as? UIImageView
var scroll : UIScrollView = view.viewWithTag(Tags.Tag_MainScroll.rawValue) as UIScrollView
var number : Int = Int(scroll.contentOffset.x / scroll.frame.size.width)
var page : UIPageControl = view.viewWithTag(Tags.Tag_page.rawValue) as UIPageControl
page.currentPage = number
println("\(page.currentPage)")
if var array : NSArray = NSUserDefaults.standardUserDefaults().objectForKey("ImageArray") as? NSArray
{
arrayImage = array.mutableCopy() as NSMutableArray
}
page.removeFromSuperview()
number++
arrayImage.removeObjectAtIndex(number)
NSUserDefaults.standardUserDefaults() .setObject(arrayImage, forKey: "ImageArray")
println("\(arrayImage[number])")
println("\(arrayImage)")
NSUserDefaults.standardUserDefaults().synchronize()
displayImage()
}